加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

windows – 在批处理脚本中执行目录列表时速度很慢

发布时间:2020-12-14 02:03:48 所属栏目:Windows 来源:网络整理
导读:你好StackOverflow成员! 我试图运行以下命令: REM the below line lists the folder names that are to be readFOR /F "TOKENS=* DELIMS=" %%d in (%start_dir%folder_list.txt) DO ( ECHO Entering into: %%d Directory REM The below line lists the fo
你好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,那就没问题了.

如果我有一个超过100GB的文件夹,脚本将花费大约一个小时来输出DIR / S>> %% d命令.

当我在大约150GB的单个文件夹上运行时:Dir / s“150GB_Folder”>> dir_ouput_file.txt它在大约6-10秒内完成.

我的问题是:为什么从脚本中输出DIR /Su0026gt;u0026gt;whatever.txt需要一个小时,而它不在脚本中只需要几秒钟?

先感谢您!

解决方法

这是一个错误,因为使用命令解析大量行会导致巨大的延迟.
解决方案是创建包含该信息的文件,然后读取该文件.

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
)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读