首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >目录清单在批处理脚本中执行时很慢

目录清单在批处理脚本中执行时很慢
EN

Stack Overflow用户
提问于 2013-09-19 20:45:16
回答 1查看 874关注 0票数 5

你好,StackOverflow会员!

我试图运行以下命令:

代码语言:javascript
复制
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只需一个小时,而如果它不在脚本中则只需几秒钟?

提前谢谢你!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-09-20 01:57:31

这是for中的一个bug,其中使用命令解析大量行会造成巨大的延迟。

解决方案是使用该信息创建一个文件,然后读取该文件。

代码语言:javascript
复制
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
)
票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18904592

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档