Page 1 of 1

Shorten file names with REN

Posted: 26 Jul 2021 14:37
by findstr
Hello!
I have files in a folder:
Listing-01-01.txt
Listing-01-02.txt
Listing-02-01.txt
Listing-02-02.txt
Listing-02-03.txt
Listing-03-01.txt
50 more similar files.
I need to rename them to be:
L01-01.txt
L01-02.txt
L02-01.txt
L02-02.txt
L02-03.txt
L03-01.txt
and do the same for all the other 50 files in the folder.
How can I do it with REN command?
Thanks!

Re: Shorten file names with REN

Posted: 26 Jul 2021 14:47
by aGerman
Tokenize the file names in a FOR /F loop.

Code: Select all

pushd "C:\your\folder"
for /f "tokens=1* delims=-" %%i in ('dir /a-d /b "Listing-*.txt"') do ren "%%i-%%j" "L%%j"
popd
Steffen

Re: Shorten file names with REN

Posted: 26 Jul 2021 17:03
by findstr
Thanks!