Move/copy files based on a list of requests

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
ovisele
Posts: 2
Joined: 09 Jan 2020 09:22

Move/copy files based on a list of requests

#1 Post by ovisele » 09 Jan 2020 09:30

Hello,

I have a folder with over 4k recordings that I need to sort based on three parameters that are inside a CSV or a TXT file. All these parameters are part of the file name.

First, I need to select the files based on the Rec number, after that based on the date of recording and finally based on the test (verSacc, antisaccades, etc). Examples of some files names below.

I am aware that I need to iterate through all files three times and pinpoint the right column in the CSV each time, but I do not know if a batch will be the right call for this or maybe another type of script...

If you guys have experience with this, I would very much appreciate a response.

Warm regards,
Ovidiu

EVALAB_Stimuli_26 feb 2017_antisaccades_Rec 01.tsv
EVALAB_Stimuli_15 ian 2018_antisaccades_Rec 02.tsv
EVALAB_Stimuli_11iulie2018_verSacc_Rec 57.tsv
EVALAB_Stimuli_11iulie2018_verSacc_Rec 61.tsv
EVALAB_Stimuli_29iulie2018_verSacc_Rec 109.tsv

jfl
Posts: 226
Joined: 26 Oct 2012 06:40
Location: Saint Hilaire du Touvet, France
Contact:

Re: Move/copy files based on a list of requests

#2 Post by jfl » 10 Jan 2020 08:53

Hi Ovisele,

It's probably feasible in Batch, but it'll be very hard.
I'd recommend that you use a more powerful language for that. (JScript, PowerShell, or Python)

If you really want to use Batch, and if you're sure the _ and . characters can never appear within one of the filename components, you can begin by extracting components this way:

Code: Select all

setlocal EnableExtensions EnableDelayedExpansion
for %%f in (EVALAB_*.tsv) do (
  for /f "delims=._ tokens=3,4,5" %%a in ("%%~f") do (
    set "FILEDATE=%%~a"
    set "FILETYPE=%%~b"
    set "RECNUM=%%~c"
  )
  rem Use the three variables using !expansion! here. Ex:
  echo FILEDATE=!FILEDATE! FILETYPE=!FILETYPE! RECNUM=!RECNUM! 
)

ovisele
Posts: 2
Joined: 09 Jan 2020 09:22

Re: Move/copy files based on a list of requests

#3 Post by ovisele » 11 Jan 2020 07:49

Thank you very much! Will definitely try this!

Post Reply