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 ) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 十二月份技术指标
- windows-7 – Windows 7上频繁的NTP同步时间
- windows – 如何在XP / Vista和更新版本上为VB6创建一个简单
- 在Windows Azure上更改http.sys注册表设置?
- active-directory – 有没有Sysinternals ADInsight的替代品
- windows-server-2003 – 无法调整从gparted启动的ntfs(Wind
- stdout – 使用Windows Script Host捕获WshShell.Exec的输出
- windows – 如何拒绝从特定计算机访问安全项?
- Windows下命令行连接mysql及导入sql文件
- 想学习Windows编程,一些建议?