У меня есть пакетный файл, который перемещает файлы от одной папки до другого. Пакетный файл сгенерирован другим процессом.
Некоторые файлы, которые я должен переместить, имеют строку "%20" в них:
move /y "\\myserver\myfolder\file%20name.txt" "\\myserver\otherfolder"
Это перестало работать, поскольку это пытается найти файл с именем:
\\myserver\myfolder\file0name.txt
Есть ли любой способ проигнорировать %
? Я не могу изменить файл, сгенерированный для выхода из этого, такой как путем удвоения знаков процента (%%
), выход с /
или ^
(каре), и т.д.
You should be able to use a caret (^) to escape a percent sign.
Editor's note: The link is dead now; either way: It is %
itself that escapes %
, but only in batch files, not at the command prompt; ^
never escapes %
, but at the command prompt it can be used indirectly to prevent variable expansion, in unquoted strings only.
The reason %2
is disappearing is that the batch file is substituting the second argument passed in, and your seem to not have a second argument. One way to work around that would be to actually try foo.bat ^%1 ^%2...
so that when a %2
is encountered in a command, it is actually substituted with a literal %2
.