我有一个批处理文件,可以使用gsutil工具将一些本地文件复制到google存储区。gsutil工具会生成一个不错的日志文件,其中显示了上载的文件的详细信息以及是否正常。
Source,Destination,Start,End,Md5,UploadId,Source Size,Bytes Transferred,Result,Description
file://C:\TEMP\file_1.xlsx,gs://app1/backups/file_1.xlsx,2018-12-04T15:25:48.428000Z,2018-12-04T15:25:48.804000Z,CPHHZfdlt6AePAPz6JO2KQ==,,18753,18753,OK,
file://C:\TEMP\file_2.xlsx,gs://app1/backups/file_2.xlsx,2018-12-04T15:25:48.428000Z,2018-12-04T15:25:48.813000Z,aTKCOQSPVwDycM9+NGO28Q==,,18753,18753,OK,
我想做的是
问题是源文件名后面附加了“ file://”,我似乎无法删除它,例如
file://C:\TEMP\file_1.xlsx
需要更改为此
C:\TEMP\file_1.xlsx
我正在使用for / f循环,并且不确定在/ / f循环中变量%% A的操作是否不同。
@echo off
rem copy the gsutil log file into a temp file and remove the header row using the 'more' command.
more +1 raw_results.log > .\upload_results.log
rem get the source file name (column 1) and the upload result (OK) from column 8
for /f "tokens=1,8 delims=," %%A in (.\upload_results.log) do (
echo The source file is %%A , the upload status was %%B
set line=%%A
set line=!line:file://:=! >> output2.txt echo !line!
echo !line!
)
输出是这样的。
The source file is file://C:\TEMP\file_1.xlsx , the upload status was OK
The source file is file://C:\TEMP\file_2.xlsx , the upload status was OK
我期望它将更改后的值转储到新文件中,但目前不产生任何结果。通常,我会使用类似这样的方法将特定字符提取到字符串的末尾,但不适用于For / f循环。
%var:~7%
非常感谢任何指针或其他方式。
由于要删除的部分似乎固定,因此使用子字符串更加容易。
还使用for /f "skip=1"
逃避命令,需要更多外部命令+1和另一个中间文件。
@echo off & setlocal EnableDelayedExpansion
type NUL>output2.txt
for /f "skip=1 eol=| tokens=1,8 delims=," %%A in (.\upload_results.log) do (
echo The source file is %%A , the upload status was %%B
set "line=%%A"
set "line=!line:~7!"
echo(!line!>>output2.txt
echo(!line!
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句