0

I have a bit of a simple but annoying problem. I am making a batch file and I am using:

dir /B /S /A:-D *.wad *.mdl *.wav *.spr *.bmp *.tga *.pcx *.mp3 *.txt *.res > sample.res

to get:

C:\Downloads\Sample1.wad  
C:\Downloads\Sample2.wav  
C:\Downloads\Folder1\Sample3.mdl  
C:\Downloads\Folder1\Folder2\Sample4.txt  

But what I really want is:

Sample1.wad  
Sample2.wav  
Folder1/Sample3.mdl  
Folder1/Folder2/Sample4.txt  

I want the sub folders included but I don't want the full path included. How can I accomplish this? Thanks.

[EDIT: Realized for my purposes I apparently need a FORWARD slash for folders instead of a BACK slash]

2 Answers2

1

Try like this :

@echo off

setlocal enabledelayedexpansion

(for /f  "delims=" %%a in ('dir /B /S /A:-D *.wad *.mdl *.wav *.spr *.bmp *.tga *.pcx *.mp3 *.txt *.res') do ( 
       set "$Path=%%a"
       set $path=!$path:%cd%=!
       echo !$path:~1!)
)>sample.res

EDIT : To have the \ replaced with / :

@echo off

setlocal enabledelayedexpansion

(for /f  "delims=" %%a in ('dir /B /S /A:-D *.wad *.mdl *.wav *.spr *.bmp *.tga *.pcx *.mp3 *.txt *.res') do ( 
       set "$Path=%%a"
       set $path=!$path:%cd%=!
       set $path=!$path:\=/!
       echo !$path:~1!)
)>sample.res
SachaDee
  • 9,245
  • 3
  • 23
  • 33
  • Worked awesomely, a major thank you! Although I now realize a new issue. Anyway to have FORWARD ( / ) slashes instead of BACK slashes ( \ ) in there at all? Either way again, a HUGE thanks. – Chez-Burjer Jul 04 '14 at 19:36
  • I know it says to avoid comments like "thanks" but doesn't seem right to let your help go un thanked so another HUGE thanks. Worked perfectly! – Chez-Burjer Jul 05 '14 at 14:51
0

This works for me :

FOR /F "tokens=*" %G IN ('dir /B /S /A:-D *.wad *.mdl *.wav *.spr *.bmp *.tga *.pcx *.mp3 *.txt *.res') DO ECHO %~nG%~xG >> sample.res
weivall
  • 917
  • 13
  • 16
  • Awesome, a thanks for the help! Any ideas on getting the file generated to use forward slashes instead of back slashes between the folders? Either way a thanks again. :-) – Chez-Burjer Jul 04 '14 at 19:41