使用批处理脚本在小文件中打印网络内容

时间:2015-06-04 09:11:50

标签: batch-file printing

我有一个脚本,可以将网络上的所有内容打印到本地文本文件中。 我需要调整此脚本,以便每个输出文件最大10 MB。

到目前为止,脚本看起来像这样:

::@ECHO OFF
echo %date% %time%  Starting %~dp0

set year=%date:~-4%
set month=%date:~3,2%
set day=%date:~0,2%
set hour=%time:~0,2%
set minute=%time:~3,2%
set second=%time:~6,2%
set folderName=%year%-%month%-%day%-%hour%-%minute%-%second%
set folderName=%folderName: =%
SET logger="%~dp0"\%folderName%.log

::Loop igjennom alle folders på nettverket, alfabetisk. Print ut innholdet i hver mappe, med full path.

set "list=N:\ O:\ P:\ R:\ V:\ Y:\ Z:\"
FOR %%i IN (%list%) DO (
    SET project=%%i & call :project
)

:project
echo Printing from %project% >> %logger%
set year=%date:~-4%
set month=%date:~3,2%
set day=%date:~0,2%
set hour=%time:~0,2%
set minute=%time:~3,2%
set second=%time:~6,2%
set folderName=%year%-%month%-%day%-%hour%-%minute%-%second%
set folderName=%folderName: =%
SET logger="%~dp0"\%folderName%.log
dir /b /a-d /s %project% > %logger%

最好的方法是在每个文件夹打印之前进行文件大小检查,如下所示:

:folder
echo Printing from %folder% >> %logger%
if (LogfileSize > 10mb) then Logfile=new Logfile.
Print folder to Logfile.

我只是不知道如何批量写这个。 如何在打印任何文件夹之前调整脚本运行:文件夹?

1 个答案:

答案 0 :(得分:0)

您可以使用for获取文件大小。但是数字可能会大于cmd可以将它们用作数字,所以你必须使用字符串比较。

for %%i in (%logger%) do set "size=0000000000%%~zi"
set size=%size:~-10%
if %size% gtr 0010485760 echo more than 10MB

显然,你应该比较一个小于10MB的数字,如果你想要添加一些仍然低于10MB的数字(多少取决于你的数据)