简体   繁体   English

Windows Batch:使用SET命令更改文件路径的一部分

[英]Windows Batch: using SET command to change part of a file path

I would like to execute a program to manipulate all images in a folder and its subfolders and save these images in another directory, but in the same subfolders structure. 我想执行一个程序来处理一个文件夹及其子文件夹中的所有图像,并将这些图像保存在另一个目录中,但是保存在相同的子文件夹结构中。 For this I need to get the full path of both the original and the processed images. 为此,我需要获取原始图像和已处理图像的完整路径。

But I simply can not get the SET command to transform the directory name. 但是我根本无法获得SET命令来转换目录名称。 Here is what I do: 这是我的工作:

set originalpath=g:\Users\PLAY\Documents\backuppgm\images
set convertpath=g:\Users\PLAY\Documents\backuppgm\resized
for /R %originalpath% %%G in (*.jpg) DO (
echo %%G
SET fullpath=%%G
SET modified=!fullpath:%originalpath%=%convertpath%!
echo Full: %fullpath%
echo Modified: %modified%

The idea is that fullpath would be equal to %originalpath%\\subfolder\\image1.jpg and that modified would be equal to %convertpath%\\subfolder\\image1.jpg I could then run my batch on these 2 items... But that set modified command does not work at all... 这个想法是,全路径将等于%originalpath%\\ subfolder \\ image1.jpg,而修改后的将等于%convertpath%\\ subfolder \\ image1.jpg然后我可以在这2个项目上运行我的批处理...但是那组修改后的命令根本不起作用...

Simply put, I would like to transform the string %originalpath%\\subfolder\\image1.jpg to %convertpath%\\subfolder\\image1.jpg 简而言之,我想将字符串%originalpath%\\ subfolder \\ image1.jpg转换为%convertpath%\\ subfolder \\ image1.jpg

thanks, 谢谢,

Blaise 布莱斯

There is two issues. 有两个问题。

1) Example of working batch (eg "test.cmd") 1)工作批次示例(例如“ test.cmd”)

@echo off
cls
set originalpath=g:\Users\PLAY\Documents\backuppgm\images
set convertpath=g:\Users\PLAY\Documents\backuppgm\resized
for /R %originalpath% %%G in (*.jpg) DO call :cvt "%%G"
goto :EOF
:cvt
echo "%~1"
SET fullpath=%~1
SET modified=!fullpath:%originalpath%=%convertpath%!
echo Full: %fullpath%
echo Modified: %modified%
goto :EOF

2) You must call it with /V:ON 2)您必须使用/V:ON调用

cmd /V:ON /c test.cmd

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM