问题描述
我尝试制作一个拖放批处理文件.
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 进行拖放的批处理文件复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!