windows - 批量更改到随机子目录

标签 windows batch-file cmd

我试图通过批处理更改到文件夹中的随机子目录

cd c:\*

不起作用,实际上每次都会将您带到回收站

if exist * (
cd *
)

没有工作

for %d in (*) do cd %d

没有工作

所以我很茫然,有没有办法批量执行此操作?

最佳答案

@echo off
setlocal EnableDelayedExpansion
rem Create an array of dir. names
set n=0
for /D %%a in (c:\*) do (
   set /A n+=1
   set dir[!n!]=%%a
)
rem Select a random element from the array
set /A d=%random%*n/32768+1
rem And CD to it
cd "!dir[%d%]!"

关于windows - 批量更改到随机子目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15049216/

相关文章:

javascript - 在 Windows 上创建 node.js 原生扩展

python - 在 virtualenv 中运行现有的 python Web 应用程序

batch-file - 抑制命令行输出

windows - 在 Windows 中将批处理文件命令拆分为多行

batch-file - CMD - 将文件从多个文件夹复制到一个文件夹

.net - System.Speech 语音合成器的奇怪问题

c# - Windows 性能计数器从 PerfMon 中消失

windows - 从命令行获取用户的非截断 Active Directory 组

batch-file - 从文件中删除以空格开头的行,包括空行

windows - 用于删除早于 N 天的文件的批处理文件