Frage

i am trying to remove prefix from all files in current folder and subfolders i tryed following code which work only for current folder

setlocal enabledelayedexpansion
for %%F in (*) do (
  set "FN=%%F"
  set "FN=!FN:~15!"
  ren "%%F" "!FN!"
)
goto :eof

Please Help me to solve this

War es hilfreich?

Lösung

for /f "delims=" %%a in ('dir /b /a-d /s') do (
    set "fname=%%~nxa"
    set "fpath=%%~dpa"
    setlocal enabledelayedexpansion
    set "nname=!fname:~15!"
    ren "!fpath!!fname!" "!nname!"
    endlocal
)

This is the safe way to preserve exclamation marks.

Andere Tipps

If you are using windows 7, you could try this:

forfiles /s /c "cmd /c ren @file @fname"

It took me a bit of time to find, but suddenly I realised that the batch file was not working because it had renamed itself!.

If this becomes an issue you could try naming the batch file zzzzzzzzz.bat which I think would prevent it from renaming itself first.

Mona

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top