我想比较两个目录之间的文件名(减扩展名),如果有匹配,将文件从两个目录中的一个复制(或移动tbd)到第三个目录。即
Dir_A有a.jpg,b.jpg,c.jpg,d.jpg,e.jpg,f.jpg
Dir_B有a.pdf,c.pdf,d.pdf,f.pdf
结果是
Dir_C得到a.jpg,c.jpg,d.jpg,f.jpg
我已经能够完成与批处理文件,但希望学习如何通过AHK。
批处理文件是:
@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发布于 2019-02-28 22:16:54
您可以使用SplitPath在变量(name_no_ext)中不使用路径、点和扩展名来存储jpg文件名,并使用FileExist()检查其他目录中是否存在具有相同名称的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
}https://stackoverflow.com/questions/54934317
复制相似问题