batch-file - 尝试创建 .bat 文件以压缩网络驱动器上的报告
问题描述
有2个驱动器:
- 网络驱动器,报告所在的位置
- 7zip 所在的本地磁盘。
此外,我们有很多用户,每个人都用不同的字母映射网络驱动器。因此,每个人的举报途径都不尽相同。
脚本和报告位于同一文件夹中。尝试创建 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.
你能建议一下,怎么做?
谢谢
解决方案
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"
推荐阅读
- java - 检查Java Streams中是否存在值,如果存在则将它们映射到整数
- javascript - 如何从 AJAX 调用接收 JSON?
- python - 如何为 torch.nn.utils.rnn.pack_sequence 转换 2D 和索引张量
- c - 欧几里德距离的 AVX 实现并与阈值比较
- java - 二叉搜索树遍历,将 InOrder、PreOrder、PostOrder、RevInOrder 组合在一个方法中
- vue.js - 如何将复选框与 v-data-table 集成 - Vuetify
- swift - 为一个单元格设置不同的布局,具体取决于其内容
- python - 为什么玩家落地时平台的速度会发生变化?
- angularjs - 在angularjs中获取“无法读取未定义的属性'缩略图'”
- assembly - 将水平和垂直线绘制到 VBE 返回的 LFB 的结果不正确