Link to home
Create AccountLog in
Avatar of djturizmo
djturizmo

asked on

How do I move only files that match the first part of their names?

Example:

 I have a directory with 3 files in it.  1.txt, 1.wav, and 2.txt,  I only want to move the files that have a matching name.  In this example I would only want it to move 1.txt and 1.wav.    Any help would be greatly appreciated.
Avatar of torimar
torimar
Flag of Germany image

Try:

move 1.* drive:\destination_folder
Avatar of djturizmo
djturizmo

ASKER

The first part of the name is constantly changing.  It will never be a constant.  This file will continously run, check for matching files and then move them.  The first time it runs, there maybe 1.txt and 1.wav, then the next time it runs, there maybe 23.txt and 23.wav.
Avatar of AmazingTech
Try this. One liner in a command prompt.

Change 2 occurance of C:\Files to your folder.
Change C:\duplicates to where you want your files to go to. Make sure the folder exist before running.

Note: Acrobat 6.txt and Acrobat 6.1.1.txt will be moved. This may only happen if you have filenames with periods in them. If you do have periods then I will need to add some more code to take care of this.
for /f "tokens=*" %a in ('dir /a-d /b "c:\files" ') DO for /f "tokens=*" %b in ('dir /a-d "c:\files\%~na.*" ^| find /c /i "%~na."') do IF %b GTR 1 MOVE "%~na.*" C:\duplicates

Open in new window

I would be moving these files to our computer from another company's computer.  Each file on their side is given a number.  These numbers are any where from 1 to 1billion.  The computer gives that number to a .txt and .wav file.  
Example 1:
123456.txt
123456.wav

Example 2:
321654.txt
321654.wav

Example 3:
456123.txt

Of the three examples, I only want to move example 1 and 2 because they have both a txt and wav.  Example 3 doesn't have a .wav, so I don't want to do anything with it.

I would be moving example 1 and 2 from a mapped drive, to our C drive.  

Also I just want to make it clear that I am not looking for duplicate files, only files that have matching .txt and .wav extentions.

Hope thats enoungh explanation.  Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Paolo Santiangeli
Paolo Santiangeli
Flag of Italy image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
AmazingTech,

It looks like it almost does what I want, but It seems like there would be something about it looking for
"%%.txt = %%.wav" and if they match, it would move them.

Thanks for your help.
psantiangeli

Thats it.  Thanks.  :)
Thanks for your help!
1. The script lists all .txt files (line 3)
2. For each .txt file, it tests if exist .wav with the same name of .txt file (line 7)
3 So, if both files exist moves the files (lines 11, 12)

%~d1 = Drive Letter
%~p1 = Path
%~n1 = Filename