你好,StackOverflow会员!
我试图运行以下命令:
REM the below line lists the folder names that are to be read
FOR /F "TOKENS=* DELIMS=" %%d in (%start_dir%\folder_list.txt) DO (
ECHO Entering into: %%d Directory
REM The below line lists the folders and all of it's subfolders. It than outputs it to a file.
FOR /F "TOKENS=* DELIMS=" %%e in ('DIR /s "%work_dir%\%%d"') DO (
ECHO %%e>>%start_dir%\tmp_folder\%%d.size
)
)上面的代码起作用。
问题是:如果我的文件夹只有几GB大小,那就没问题了。
如果我有一个大于100 to的文件夹,那么脚本输出DIR /S>>%%d命令大约需要一个小时。
当我在一个大约150 /s的文件夹上运行: Dir /s "150GB_Folder">>dir_ouput_file.txt时,它在大约6-10秒内完成。
我的问题是:为什么在脚本中输出DIR /S>>whatever.txt只需一个小时,而如果它不在脚本中则只需几秒钟?
提前谢谢你!
发布于 2013-09-20 01:57:31
这是for中的一个bug,其中使用命令解析大量行会造成巨大的延迟。
解决方案是使用该信息创建一个文件,然后读取该文件。
REM the below line lists the folder names that are to be read
FOR /F "TOKENS=* DELIMS=" %%d in (%start_dir%\folder_list.txt) DO (
ECHO Entering into: %%d Directory
REM The below line lists the folders and all of it's subfolders. It than outputs it to a file.
DIR /s "%work_dir%\%%d" >%temp%\temp.tmp
FOR /F "TOKENS=* DELIMS=" %%e in (%temp%\temp.tmp) DO (
ECHO %%e>>%start_dir%\tmp_folder\%%d.size
)
del %temp%\temp.tmp
)https://stackoverflow.com/questions/18904592
复制相似问题