0

I have searched on this forum but not been able to recognize what I am looking for. IRC dosen't allow the DCC of the files having spaces. How to create a batch file which replace spaces with underscore for all the MP3/FLAC files in the folder. I tried this but failed

@echo off
Setlocal enabledelayedexpansion
Set "Pattern= "
Set "Replace=_"
For %%a in (*.mp3) Do (
Set "File=%%~a"
Ren "%%a" "!File:%Pattern%=%Replace%!"
)
Pause&Exit

It's giving me the error that the files are being used by another process though the files were not used by any programs and now it ain't doing anything whenever I run it it just says "press any key to continue and shuts down"

Any help? thanks.

ViSiON
  • 1
  • 1
  • 2
  • 1
    Try to change the `Set` line to `Set "File=%%~nxa"`, so only the file name is stored; then, change the `"%%a"` in the `Ren` line to `"%%~fa"` to provide the full path to the command; all this excludes any path-related trouble... – aschipfl Sep 19 '15 at 11:35

1 Answers1

0

Check with echo in front of rename command. It should works.

But if you are getting the files are being used by another process. This is certainly the case.

This can be an application blocked on closing, application hidden in systray, windows search indexer.
Restart or logoff computer may solve.

@echo off
setlocal enabledelayedexpansion
set "pattern= "
set "replace=_"
for %%a in (*.mp3) do (
  set "file=%%~nxa"
  echo Ren "%%~fa" "!file:%pattern%=%replace%!"
  ::pause
)
pause
exit /b 0
Paul
  • 2,620
  • 2
  • 17
  • 27