-2

I currently have over 100.000 files (.bak) which I need to move 1000 files to a different directory. The files that need to be moved have a twin-file with a different extension (.xml) so finding them should be easy, but for the life of me I can't figure out how to do this. I have no experience with .bat-files and I've already been struggling with stuff for a day. Can someone help me out please?

Quick example:

First file:

File1thatneedstomove.bak
File1thatneedstomove.xml
File1thatdoesntneedstomove.bak
File2thatdoesntneedstomove.bak
File3thatdoesntneedstomove.bak
File2thatneedstomove.bak
File2thatneedstomove.xml

So I need to move the 1st and 6th file to a different folder because they have a twin file where just the text behind the period is different.

Jay Oever
  • 3
  • 1
  • Welcome to SO. This site is not a code-writing service and is not meant for delivering complete solutions. Users are expected to show some effort and code whilst SO is here to help you solve specific programming problems along the way. What have you tried already? Please read: https://stackoverflow.com/help/asking – Maciej Jureczko Oct 18 '17 at 07:20
  • I tried copying these two solutions and change them to suit my needs but this doesn't seem to work. I can't check how to compare two files and then move based on that check.https://stackoverflow.com/questions/28035754/batch-file-to-move-files-based-on-name-w-o-creating-new-folders and https://stackoverflow.com/questions/41804814/batch-file-to-move-files-based-on-part-of-filename-to-folder-based-on-part-of-f – Jay Oever Oct 18 '17 at 07:46

1 Answers1

2

Not tested:

set "source_dir=C:\baks"
set "destination=C:\dest"

for %%a in ("%source_dir%\*bak") do (
   if exist "%%~dpna.xml" (
      echo move /y "%%~fa" "%destination%"
   )
)

It will echo the needed move command parameters. If it is ok remove echo word in the line in the brackets.

npocmaka
  • 55,367
  • 18
  • 148
  • 187