问题描述
我尝试制作一个拖放式批处理文件.
I tried to make a drag-and-drop batch file.
我遇到文件存在但批处理文件找不到的问题...
I have the problem that a file exists but the batch file couldn't find it...
我想将 .png
文件(如 pict_2013020808172137243.png
)复制到另一个文件夹并重命名.
I want to copy .png
files (like pict_2013020808172137243.png
) to another folder and rename it.
路径中有_
之类的符号和空格,我也不知道怎么做多次拖放来实现相同的功能(重命名并添加到.邮编
).
In the path are symbols like _
and spaces, also I don't know how to make multi-drag-and-drop to make the same function (rename and add to .zip
).
我试过了,但没有结果:(
I tried this but with no result :(
@ECHO OFF
ECHO %1
COPY "%1" "%CD% est" /Y /S
REN "%CD%mob*.png" "%CD% est est.png"
7za u -tzip "%appdata%.virtopack.zip" "test" -r
推荐答案
Drag &drop 对批处理文件的实现很糟糕.
如果存在空格,则引用名称,但如果找到特殊字符则不引用,例如 &,;^
Drag & drop is badly implemented for batch files.
The names are quoted, if a space is present, but not if a special character is found, like &,;^
对于文件名中的空格,您只需稍微更改代码即可.
For spaces only in your filenames, you need to change your code only a bit.
@ECHO OFF
ECHO "%~1"
COPY "%~1" "%CD% est" /Y /S
MOVE "%CD%mob*.png" "%CD% est est.png"
7za u -tzip "%appdata%.virtopack.zip" "test" -r
%~1
总是扩展到一个不带引号的版本,所以总是可以以安全的方式引用它们.
%~1
expands always to an unquoted version, so can always quote them in a safe way.
"c:Docs and sets" -> %~1 -> c:Docs and sets -> "%~1" -> "c:Docs and sets"
c:Programs -> %~1 -> c:Programs -> "%~1" -> "c:Programs"
有关详细信息,请阅读拖放多个文件的批处理文件?
这篇关于批处理文件复制使用 %1 进行拖放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!