Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
208 views
in Technique[技术] by (71.8m points)

Batch file to check files with same name

I've a folder where every archive file has a correspondant image file with the same name. If ordered by file name then the structure of the folder is:

  • Folder
    • File1.zip
    • File1.jpg
    • File2.zip
    • File2.jpg
    • File3.zip (this file should be moved to a subfolder)
    • File4.zip
    • File4.jpg

If the archive file has not its image file then it should be moved to another folder.

One problem is that not all archive files are .zip, but also .rar or 7z and not all images are .jpg but also .jpeg or .png

It would be great if you could point me to the solution because I'm a web designer and .bat files are not really my domain :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

While [SO] isn't a script writing service, I did find the task interessent.
Adapt the pathes in line 2+3 in the following batch to your environment.

@Echo off&SetLocal 
PushD "X:folder	ocheck"
Set "MoveToFolder=Y:movearc	o"
For /f "delims=" %%Z in ('Dir /B *.zip *.rar *.7z') Do (
  Set "FoundPic="
  For /f "delims=" %%P in (
    'Dir /B "%%~nZ*" ^| findstr /i ".jpg$ .jpeg$ .png$" '
  ) Do Set FoundPic=yes
  If not defined FoundPic echo Move "%%Z" "%MoveToFolder%"
)
PopD

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...