# Follow up "Solved: Rename beginning of a filename from batch or command prompt"



## pasc (Jun 21, 2014)

Well, here is a more complicated matter of this threads problem.

http://forums.techguy.org/dos-other...ng of a filename from batch or command prompt

I have files that contain this: "- Verknüpfung"

and I want to rename them so that part is deleted.

is this possible with DOS ?


----------



## foxidrive (Oct 20, 2012)

The link doesn't work here.

Your character set seems to contain characters that may need another code page, and some batch file utilities and techniques will also fail with them.

Are these files in a tree or a single folder?


----------



## pasc (Jun 21, 2014)

you are right:

http://forums.techguy.org/dos-other/965668-rename-beginning-filename-batch-command.html

The files are all in the same folder


----------



## foxidrive (Oct 20, 2012)

This uses a helper batch file called `repl.bat` (by dbenham) - download from: https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat

Place `repl.bat` in the same folder as the batch file or in a folder that is on the path.

It is untested - change the *.dat in two spots to your filespec - and it will only show you the ren commands on the screen. 
If the ren commands are right then remove the  echo( and run it again.


```
@echo off
dir *.dat /b /a-d >file1.txt
dir *.dat /b /a-d | repl "- Verkn.pfung" "" >file2.txt 

setlocal DisableDelayedExpansion
< file2.txt (
   for /F "delims=" %%a in (file1.txt) do (
      set file2Line=
      set /P file2Line=
      set "file1Line=%%a"
      setlocal EnableDelayedExpansion   
      echo( ren "!file1Line!" "!file2Line!"
      endlocal
   )
)
pause

del file1.txt
del file2.txt
```


----------



## pasc (Jun 21, 2014)

I have a file called "SkypePortable.exe - Verknüpfung.lnk"
https://dl.dropboxusercontent.com/u...os/rename/SkypePortable.exe - Verknüpfung.lnk

Your batch will mention my file, but fail to change it's name.


----------



## foxidrive (Oct 20, 2012)

foxidrive said:


> If the ren commands are right then remove the  echo( and run it again.


Did you see the above?

Were there any error messages on the screen?


----------



## pasc (Jun 21, 2014)

Perfect ! Thanks


----------

