Solved rename filename.xxx.info to file_name.nfo in every folder

January 9, 2012 at 04:58:26
Specs: Windows 7, 16GB
lets say i'm currently in folder c:/test

and i have the current files
c:/test/folder1/filename1.avi.info
c:/test/folder2/filename2.xls.info
c:/test/folder3/folder4/filename3.docx.info

i would like to run the batch file in c:/test and it should go through all folders and rename all the files from filename.xxx.info to filename.nfo

eg .... the above examples should become

c:/test/folder1/filename1.nfo
c:/test/folder2/filename2.nfo
c:/test/folder3/folder4/filename3.nfo

thanks in advance for your help.


See More: rename filename.xxx.info to file_name.nfo in every folder

Report •


✔ Best Answer
January 9, 2012 at 23:58:45
1. Done.
2. Done.


can we write another script so that it always repaces the last 8 chars with .nfo?

If the last 8 chars are replaced by .nfo the filename/extension will be Filename1..nfo (note the two ..), is that what you want?

Why 8 chars? As shown in your original post docx.info is 9 chars long. Are the docx files not to be renamed?

@echo off
setlocal enabledelayedexpansion enableextensions

if not "%cd%" equ "C:\test\" pushd c:\test\||echo pushd failed.&&exit /b

for /f "tokens=*" %%1 in ('dir /a-d /b /s *.info') do (
    set oldname=%%1

    set intname=%%~n1

    for /f "tokens=*" %%A in ("!intname!") do (
        set newname=%%~nA.nfo

    ren "!oldname!" "!newname!"
  )
)


Please come back & tell us if your problem is resolved.



#1
January 9, 2012 at 08:33:11
Just to say you should always use back slashes in MS-DOS, Command Prompt or batch files (except for "switches").


Report •

#2
January 9, 2012 at 14:13:01
Please test this script. Note that the filename must not include the . (fullstop) character.

@echo off
cls

setlocal enabledelayedexpansion enableextensions

if not "%cd%" equ "C:\test\" pushd c:\test\||echo pushd failed.&&exit /b

for /f "tokens=*" %%1 in ('dir /a-d /b /s *.info') do (
    set oldname=%%1

    for /f "tokens=1-4* delims=\." %%1 in ("!oldname!") do (
        set newname=%%4.nfo

        ren "!oldname!" "!newname!"
  )
)


Please come back & tell us if your problem is resolved.


Report •

#3
January 9, 2012 at 18:35:24
wahine - this is great - close to perfect my friend !

did some testing -

1. i definitely need it to work for .(fullstop) in file name ... have many of those ..
can we write another script so that it always repaces the last 8 chars with .nfo eg -
file is "this.is.my-file name.avi.info" becomes "this.is.my-file name.nfo" so we will always have to replace "avi.info" which will always be avi(3)+fullstop(1)+info(4) with .nfo ?

2. Also it does not work on nested folders
adding to my example above will be
c:\test\folder1\folder1_11\filename1.avi.info and
c:\test\folder1\folder1_11\folder_111\filename1.avi.info
should both be fixed.

but nevertheless great attempt. Its really close to what i'm looking for. #2 above is an enhancement.

thx and keep up the great work.


Report •

Related Solutions

#4
January 9, 2012 at 18:35:59
Derek : thanks i will remember that

Report •

#5
January 9, 2012 at 23:58:45
✔ Best Answer
1. Done.
2. Done.


can we write another script so that it always repaces the last 8 chars with .nfo?

If the last 8 chars are replaced by .nfo the filename/extension will be Filename1..nfo (note the two ..), is that what you want?

Why 8 chars? As shown in your original post docx.info is 9 chars long. Are the docx files not to be renamed?

@echo off
setlocal enabledelayedexpansion enableextensions

if not "%cd%" equ "C:\test\" pushd c:\test\||echo pushd failed.&&exit /b

for /f "tokens=*" %%1 in ('dir /a-d /b /s *.info') do (
    set oldname=%%1

    set intname=%%~n1

    for /f "tokens=*" %%A in ("!intname!") do (
        set newname=%%~nA.nfo

    ren "!oldname!" "!newname!"
  )
)


Please come back & tell us if your problem is resolved.


Report •

#6
January 11, 2012 at 18:19:45
Wahine, this is great - your right - constraining it to 8 chars might come back to bite me - thank you thank you thank you ,,, your superb at what you do. thx again.

Report •


Ask Question