1

I'm trying to drag both folders and files onto a batch file and want to process the filetypes .flac .mp3 .acc only if the directories/subdirectories contain these filetypes.

Recursive processing is what I was after also.

Dir tree looks like:

Z:\Music\
|   03 - I Love You (Booka Shade Remix).mp3
|   02 - Towers.mp3
|
+---Woodkid - 2013 - I Love You [FLAC]
|       cover.jpg
|       02 - Towers.flac
|       01 - I Love You.flac
|       03 - I Love You (Booka Shade Remix).flac
|
+---No FLAC, MP3 or ACC folder
|       cover.jpg
|
\---Woodkid - 2013 - I Love You [MP3]
|       cover.jpg
|       01 - I Love You.mp3
|       02 - Towers.mp3
|       03 - I Love You (Booka Shade Remix).mp3
|
\---Woodkid - 2013 - I Love You [ACC]
|        cover.jpg
|        01 - I Love You.acc
|        02 - Towers.acc
|        03 - I Love You (Booka Shade Remix).acc

I wanted to process the directory tree above like so with files in numerical order.

Processing Directory: Z:\Music\
   Processing File: 1 - 02 - Towers.mp3
   Processing File: 1 - 03 - I Love You (Booka Shade Remix).mp3
Processing Directory: Woodkid - 2013 - I Love You [FLAC]
   Processing File: 1 - 01 - I Love You.flac
   Processing File: 1 - 02 - Towers.flac
   Processing File: 1 - 03 - I Love You (Booka Shade Remix).flac
Processing Directory: Woodkid - 2013 - I Love You [MP3]
   Processing File: 1 - 01 - I Love You.mp3
   Processing File: 1 - 02 - Towers.mp3
   Processing File: 1 - 03 - I Love You (Booka Shade Remix).mp3
Processing Directory: Woodkid - 2013 - I Love You [ACC]
   Processing File: 1 - 01 - I Love You.acc
   Processing File: 1 - 02 - Towers.acc
   Processing File: 1 - 03 - I Love You (Booka Shade Remix).acc

I've tried to get this to work with help from this post but that's for single file types only.

EDIT: My attempt. Notes and questions inside the code:

@echo off
FOR %%I IN (%*) DO (
    ECHO.%%~aI | FIND "d" >NUL
    IF ERRORLEVEL 1 (
        :: Processing Dropped Files
        :: Only need folder (%%~dpI) to repeat once, this repeats for every dropped file.
        echo %%~dpI
        :: Would be nice if I could set a variable for file types at beginning of script
        for /f "tokens=*" %%I in ('DIR /B/OGDN "%%~nI.flac" "%%~nI.mp3" "%%~nI.acc" 2^>NUL') DO (
            echo   Processing File: %%I
            )
        ) ELSE (
        :: Processing Dropped Folders
        :: Need the directory echod here (just once).
        :: Don't know how to process flac mp3 or acc files within the dropped folder recursively.
        :: Be nice if I could set a variable for file types here too.
        )
        )
@pause
Ste
  • 1,729
  • 1
  • 17
  • 27

1 Answers1

1

If it is for a few extensions only, this should do. if you have many extensions, then it would be easier to build a list and run a single if statement.

@echo off
for /f "tokens=*" %%i in ('dir /b /a-d /s %*') do (
  if "%%~xi"==".flac" echo "%%i"
  if "%%~xi"==".mp3" echo "%%i"
  if "%%~xi"==".acc" echo "%%i"
 )
pause

Obviously you will replace echo with your actual command.

EDIT

This will not be very fast as it has 3 loops, but should work.

@echo off
set "list=.flac .mp3 .aac"
for %%a in (%*) do (
if exist .\nul @echo Processing Directory: %%a
 for /f "tokens=*" %%i in ('dir /b /a-d /s %*') do (
   for %%j in (%list%) do (
    if "%%~xi"=="%%j" echo File Type is %%j - Processing file: "%%i"
   )
  )
 )
pause

If you would want to display filename only in the Processing file: section, simply change %%i to %%~nxi

Gerhard
  • 22,678
  • 7
  • 27
  • 43
  • Thanks. I didn't get close to getting `%*` in `for /f "tokens=*" %%i in ('dir /b /a-d /s %*') do ()` to work. How would one build a list and run a single if statement? I've no idea how to get that to work. I've searched for a solution but came up with nothing. Also, how could I output the directory to cmd like the starting post only once and not for each file in the folder? I edited that to show my attempt also along with notes on whats wrong. Thanks. – Ste Apr 23 '18 at 22:33
  • @StephenSherry did you copy my code exactly? if you did it would have worked. The script processes each directory you drag to the batch file as well as actual files. We can do a list, but please try and get this to work first by copying the code exactly as is. – Gerhard Apr 24 '18 at 06:06
  • I did thanks. It works. It doesn't echo the folder name and file name as per starting post structure. Also, the list would be useful as each of the files are processed with the same code. – Ste Apr 24 '18 at 09:50
  • I am also not getting paid to do everything. So I am simply helping into the right direction. :) – Gerhard Apr 24 '18 at 10:28
  • When I said it works (it does) just not as intended. The heading cannot fit all of the problems I encountered into that when trying to get it to work. Thanks for your help. – Ste Apr 24 '18 at 10:43
  • `if exist .\nul @echo Processing Directory: %%a` is listing dragged files. I assume the `.\nul` part checks this, but it's not working. Also, it goes back to the same problem I had before it echoes directories without the filetypes inside. It also doesn't work recursively, another problem I had with drag and drop. Thanks, – Ste Apr 24 '18 at 16:05
  • What windows version are you using? Did you copy the code as is? – Gerhard Apr 24 '18 at 16:11
  • Yes, exactly as is. Windows 10 Pro latest. Build 16299. – Ste Apr 24 '18 at 16:34