比较不同目录中的文件名(减去扩展名),如果使用AutoHotkey复制/移动相同的文件名
我想比较两个目录之间的文件名(减去扩展名),如果存在匹配项,则将文件从两个目录之一复制(或移动[tbd])到第三个目录。i、 e 迪鲁A有A.jpg,b.jpg,c.jpg,d.jpg,e.jpg,f.jpg 目录B有a.pdf、c.pdf、d.pdf、f.pdf 结果将是 Dir_C得到a.jpg,C.jpg,d.jpg,f.jpg 我已经能够通过批处理文件来完成这一点,但我想学习如何通过AHK 批处理文件是:比较不同目录中的文件名(减去扩展名),如果使用AutoHotkey复制/移动相同的文件名,autohotkey,Autohotkey,我想比较两个目录之间的文件名(减去扩展名),如果存在匹配项,则将文件从两个目录之一复制(或移动[tbd])到第三个目录。i、 e 迪鲁A有A.jpg,b.jpg,c.jpg,d.jpg,e.jpg,f.jpg 目录B有a.pdf、c.pdf、d.pdf、f.pdf 结果将是 Dir_C得到a.jpg,C.jpg,d.jpg,f.jpg 我已经能够通过批处理文件来完成这一点,但我想学习如何通过AHK 批处理文件是: @Echo Off & SetLocal EnableExtensions
@Echo Off & SetLocal EnableExtensions
pushd D:\temp
For /F "tokens=*" %%I IN ('dir /a-d /b *.jpg') DO (
IF EXIST "D:\temp\comp\%%~nI.pdf" move "%%~I" "D:\temp\new\"
)
经过大量的寻找,找到类似的帖子,并尝试插入,我想我已经接近了,但显然遗漏了一些东西。我希望有人能帮我解释一下
#NoEnv
SendMode Input
SFolder:="D:\temp\" ;Source folder
CFolder:="D:\temp\comp" ;Compare folder
DestDir:="D:\temp\new" ;where to move files
Loop,
{
Loop, %SFolder%*.jpg ;look for all jpg files
JpgName = %A_LoopFileName% ;save the file names to var
Loop, %CFolder%*.pdf ;look for all pdf files
PdfName = %A_LoopFileName% ;save the file names to var
JpgCompare:=Trim(JpgName,".jpg") ;remove the files .ext
PdfCompare:=Trim(PdfName,".pdf") ;remove the files .ext
If JpgCompare = %PdfCompare% ;if there are matching file names (minus .ext)
;in both directories
{
FileMove, %JpgName%, %DestDir% ;move the file.jpg to the "new" directory
}
Else
{}
}
Esc::
ExitApp
您可以使用将jpg文件名(不带路径、点和扩展名)存储在变量(name_no_ext)中,并使用以下命令检查其他目录中是否存在同名的pdf文件:
SFolder:="D:\temp\" ;Source folder
CFolder:="D:\temp\comp" ;Compare folder
DestDir:="D:\temp\new" ;where to move files
Loop Files, %SFolder%*.jpg ;look for all jpg files
{
SplitPath, A_LoopFileName,,,, name_no_ext
If FileExist(CFolder . "\" . name_no_ext . .pdf)
FileMove, %A_LoopFileFullPath%, %DestDir% ;move the file.jpg to the "new" directory
}