Batch file 尝试创建.bat文件以压缩网络驱动器上的报告
有2个驱动器:Batch file 尝试创建.bat文件以压缩网络驱动器上的报告,batch-file,cmd,Batch File,Cmd,有2个驱动器: 报告所在的网络驱动器 本地磁盘,7zip所在的位置 另外,我们有很多用户,每个人都用不同的字母映射网络驱动器。因此,报告的路径对每个人都不一样 脚本和报告位于同一文件夹中。 尝试创建script.bat以在网络驱动器上存档报告。以下是我所拥有的: @echo off ::set a path to network shared directory pushd \\IP_address\path_to_reports set BEpath= %cd% :: Move fi
- 报告所在的网络驱动器
- 本地磁盘,7zip所在的位置
@echo off
::set a path to network shared directory
pushd \\IP_address\path_to_reports
set BEpath= %cd%
:: Move files to temporary directory FilesToZip
mkdir "%BEpath%\FilesToZip"
move %BEpath%\report_Germany_??_%1_??.txt %BEpath%\FilesToZip\
:: Archive files
cd /d "C:\Program Files\7-Zip"
7z a -t7z "%BEpath%\archive.7z" "%BEpath%\FilesToZip\*.txt"
如果我只使用CD\\server\path
而不是pushd\\IP\u地址\path\u to\u报告
,则会出现错误
CMD不支持将UNC路径作为当前目录。
看起来它无法从C:\drive在网络驱动器上压缩,并出现错误:
7-Zip 19.00 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2019-02-21
Scanning the drive:
WARNING: The filename, directory name, or volume label syntax is incorrect.
Z:
0 files, 0 bytes
Creating archive: Z:\path\archive.7z
Add new data to archive: 0 files, 0 bytes
Scan WARNINGS for files and folders:
Z: : The filename, directory name, or volume label syntax is incorrect.
----------------
Scan WARNINGS: 1
Error:
cannot open file
Z:\path\archive.7z
The filename, directory name, or volume label syntax is incorrect.
你能告诉我怎么做吗
谢谢你你有几个选择 1) 您可以分析
drivetype
=4(网络驱动器)的wmic logicaldisk get caption、drivetype、providername
的输出,其中providername
='\IP\U地址\path\U to\U报告'。然后,caption
将有它们的映射驱动器号供您直接使用。请注意,WMIC
已被弃用,因此有一天这种方法将不再适用于您
2) 你可以自己重新映射到一个不太可能的字母。我发现几乎没有人使用A:
net use a: \\IP_address\path_to_reports
set BEpath=a:\
...do stuff here...
net use a: /delete
7z本机支持UNC路径 不要尝试使用pushd创建的临时驱动器:
7z a -t7z "%BEpath%\archive.7z" "%BEpath%\FilesToZip\*.txt"
直接使用UNC路径:
set "UNCpath=\\IP_address\path_to_reports"
7z a -t7z "%UNCpath%\archive.7z" "%UNCpath%\FilesToZip\*.txt"
在集合字符串中移动双引号,以包含变量名
set“UNCpath=\\IP\u address\path\u to\u reports”
@Gerhard Barnard,谢谢您的帮助。它测试正常,所以我甚至没有注意到打字错误。更新了,伙计们<代码>“UNCpath=\\IP\u地址\path\u to\u报告”-工作正常。