dimanche 16 août 2020

How to select randomly a certain number of files (same filename but 4/5 different extensions) and move them to another folder?

My situation:

A directory with hundreds of files with descriptive, different names but always the same extensions (example):

LetItBe(TheBeatles).mid LetItBe(TheBeatles).jpg LetItBe(TheBeatles).ran LetItBe(TheBeatles).zip LetItBe(TheBeatles)Scan.mid (Scan would always be at end of filename and always the same word)

Next group:

HeyJude(TheBeatles).mid HeyJude(TheBeatles).jpg HeyJude(TheBeatles).ran HeyJude(TheBeatles).zip HeyJude(TheBeatles)Scan.mid etc.

I want the batch to

Randomly select a number of files (say 10) and copy ALL of the associated files (i.e. the two MID, the jpg, the ran, the zip) with the same filename to a different directory.

I don't want the batch to stop if, for example, one of the groups of files is missing the jpg file or the mid file, but just to copy the existing files to the new folder and move on to the next randomly selected group.

I've found a batch code that works in moving one MIDI file randomly, but I'm not sure how to insert the code that specifies all files with the same filename but different extensions should also be moved...

@echo off
set folder=C:\Test1
set destfolder=C:\Test2

for /f "delims=" %%C in ('dir /b /a-d "%folder%\*.mid" ^| find /c /v ""') do set /A num=%random% %% %%C
for /f "delims=" %%F in ('dir /b /a-d "%folder%\*.mid" ^| more +%num%') do set name=%%F & goto next

:next

echo (By the way, I chose %name% )
move "%folder%\%name%" "%destfolder%\%name%"

User Mofi kindly offered this help..

The command to copy all files starting with same string is copy "%FileName%." "C:\Destination Folder" with environment variable FileName being defined by the code selecting randomly one of the file groups, for example, with set "FileName=HeyJude(TheBeatles)". More safe would be using two COPY command lines: copy "%FileName%.*" "C:\Destination Folder" and copy "%FileName%Scan.mid" "C:\Destination Folder" 2>nul in case of there are the file sets HeyJude(TheBeatles) and HeyJude(TheBeatles) Live and file set HeyJude(TheBeatles) should be copied to destination folder.

But I can't figure out how to insert it into the existing code. I tried editing the last line to be

move "%folder%\%name%*.*

But then no files at all are moved and the system can't find any matching filename.

Help appreciated!




Aucun commentaire:

Enregistrer un commentaire