0

This might look as a usual question here in stackflow but it's a bit different on how it operates. I got over a half-a-million+ and counting wav files which I need to sort. All files are stored in a single directory and files are named like:


OUT60105-20151109-161938-144XXXXXXX.70572.WAV

This file was generated from a call on team member's Extension 60105 (OUT60125) on 20151109 (date-of-recording) and the callers Team leader name is Boyly.


OUT60168-20151110-161850-144XXXXXXX.70570.WAV

This file was generated from a call on team member's Extension 60168 (OUT60168) on 20151110 (date-of-recording) and the callers Team leader is Girly.


and so forth...

So with the information above, I'd like to sort all those files to a directory structure below:

F:\Recordings\Team Leader's name\Team member's Extension\date-of-recording

This is what I have so far and honestly, I don't know what's next to perform:

@echo off
setlocal enabledelayedexpansion
set FolderIncoming=F:\Incoming_Rec
set FileMask=OUT*.WAV
set FolderSorted=F:\Recordings\TeamLeader

for %%a in ("%FolderIncoming%\%FileMask%") do (

      Set FileName=%%~a


  for /f "tokens=1-2 delims=-" %%b in ("%%~nxa") do (                 

          if not exist "%FolderSorted%\%%e\%%b\%%~na.WAV" (
          if not exist "%FolderSorted%\%%e\%%b" md "%FolderSorted%\%%e\%%b"
          copy "%%a" "%FolderSorted%\%%e\%%b"
          )

       )
)

How can I go with this? Please note that I have several team leaders and on their team are several members (extensions) as well.

Itchy Foot
  • 13
  • 3
  • 1
    Indicate the "161938" the name "Boyly" and "161850" = "Girly"? How many Team leaders exist (approx)? – Aacini Nov 10 '15 at 14:03

1 Answers1

0

EDIT: Copy only those recordings from Extension listed in the array

@echo off
setlocal enabledelayedexpansion

rem Create the array of Team leader names
for %%a in ("161938=Boyly"
            "161850=Girly") do (
   for /F "tokens=1,2 delims==" %%b in (%%a) do (
      set "name[%%b]=%%c"
   )
)

set FolderIncoming=F:\Incoming_Rec
set FileMask=OUT*.WAV
set FolderSorted=F:\Recordings

for %%a in ("%FolderIncoming%\%FileMask%") do (

   for /f "tokens=1-3 delims=-" %%b in ("%%~NXa") do (

      set "leader=!name[%%d]!"

      rem Copy only those recordings from Extension listed in the array
      if defined leader (

         if not exist "%FolderSorted%\!leader!\%%b\%%c\%%~Na.WAV" (
            if not exist "%FolderSorted%\!leader!\%%b\%%c" md "%FolderSorted%\!leader!\%%b\%%c"
            copy "%%a" "%FolderSorted%\!leader!\%%b\%%c"
         )

      )

   )

)

You may read further details on array management in Batch files at this post.

Community
  • 1
  • 1
Aacini
  • 65,180
  • 12
  • 72
  • 108
  • Hi Aacini, right now I have 7 team leaders. The script executed well but it does not create the Team leader's name sub-folder. It only creates as follows: F:\Incoming_Rec\OUT60105\20151110 w/c supposedly should create F:\Incoming_Rec\Boyly\OUT60105\20151110. – Itchy Foot Nov 11 '15 at 05:26
  • I made a test in my computer and it works correctly. See the edit in my answer... – Aacini Nov 11 '15 at 20:56
  • Is there a way in which the codes above will copy only those recordings from Extension listed in the array ("161938=Boyly","161850=Girly")? All other recordings not included in the array will be left out in the Folder_Incoming. – Itchy Foot Nov 12 '15 at 08:05