首页 > 解决方案 > 尝试创建 .bat 文件以压缩网络驱动器上的报告

问题描述

有2个驱动器:

此外,我们有很多用户,每个人都用不同的字母映射网络驱动器。因此,每个人的举报途径都不尽相同。

脚本和报告位于同一文件夹中。尝试创建 script.bat 以在网络驱动器上存档报告。这是我所拥有的:

@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_address\path_to_reports它会给出错误

CMD does not support UNC paths as current directories.

看起来它无法从 C:\ 驱动器压缩到网络驱动器并给出错误:

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.

你能建议一下,怎么做?

谢谢

标签: batch-filecmd

解决方案


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"

推荐阅读