您好,我正在尝试制作一个批处理文件,它会挖掘一个目录并检查其子目录中的所有文件是否与另一个目录中的文件相同(具有相同的名称和相同的子目录名称)
例如:
C:/Users/Administrator/desktop/directory1/global/config/project.config
C:/directory2/global/config/project.config
我能够获取所有需要与 for 循环进行比较的文件 echo %%f 给了我一条像这样的路径:
C:/Users/Administrator/directory1/global/config/project.config
但我想删除开头并将其存储在一个新变量中,以便我可以轻松地使用 FC 命令比较文件。我不知道如何在 for 循环中正确地进行字符串替换。我只想得到这个:
/global/config/project.config
我现在的代码
set b="c:\Users\Administrator\desktop\"
set j=""
for /f %%f in ('dir /a:-d /s /b /r c:\Users\Administrator\desktop\global') do (
set c=%%f
%c:b=j%
echo %%c
)
最佳答案
@echo off
set "dir1=c:\smth"
set "dir2=c:\dir\smth2"
setlocal enableDelyaedExpansion
for /f %%F in ('dir /a:-d /s /b /r "%dir1%"') do (
set "file_path=%%F"
if not exist "!file_path:%dir1%=%dir2%!" (
echo file %%F does not exists in %dir2%
)
)
endlocal
关于windows - 修改for循环批处理文件中的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19302303/