1.

Solve : rename files in a folder stucture?

Answer»

Hello,

I do not know BAT commands and I need to go through a folder structure and recursevly find all files and rename them, I MEAN if the file name has special characters ( ?<>@#$ also space) I need to rename them into an underscore

This is untested - it should get you started.

At the moment it just ECHOES to the screen and pauses between each file. Press space and watch the echo commands to see if that is what you want to do.
If it is then remove the 'echo' and the 'pause'

Code: [Select]@echo off
for /f "delims=" %%a in ('dir /a:-d /o:N /b /s') do call :next "%%a"
GOTO:EOF
:next
set "newname=%~nx1"

set "newname=%newname: =_%"
set "newname=%newname:)=_%"
set "newname=%newname:(=_%"
set "newname=%newname:&=_%"
set "newname=%newname:^=_%"
set "newname=%newname:$=_%"
set "newname=%newname:#=_%"
set "newname=%newname:@=_%"
set "newname=%newname:!=_%"
set "newname=%newname:-=_%"
set "newname=%newname:+=_%"
set "newname=%newname:}=_%"
set "newname=%newname:{=_%"
set "newname=%newname:]=_%"
set "newname=%newname:[=_%"
set "newname=%newname:;=_%"
set "newname=%newname:'=_%"
set "newname=%newname:`=_%"
set "newname=%newname:,=_%"

echo ren %1 "%newname%
pause



Discussion

No Comment Found