2013-02-24 96 views
1

我試着去改變任何的子目錄的文件夾中有一批變化隨機子目錄批量

cd c:\* 

不工作,其實每次帶你到回收站

if exist * (
cd * 
) 

didnt工作

for %d in (*) do cd %d 

沒有工作

所以即時消失,有沒有辦法批量做到這一點?

回答

2
@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%]!" 
+0

+1你比我更有效率。 – rojo 2013-02-24 15:41:04

+0

完美!正是我需要的 – user2103892 2013-02-24 22:10:08

2
setlocal enabledelayedexpansion 
set c=0 
rem count dirs in c:\ 
for /d %%I in (c:\*) do set /a c+=1 >NUL 
set /a c=%RANDOM% * %c%/32768 + 1 >NUL 
set loop=0 
for /d %%I in (c:\*) do (
    set /a loop+=1 
    if !loop!==%c% cd /d "%%I" 
)