Solved Batch Script to rename file extensions

Asus / Rampage iv extreme x79
August 16, 2016 at 01:32:59
Specs: Windows 10 64 bit, 3.601 GHz / 16324 MB
Hi all,

I was hoping you can help me with my struggle trying to write a batch script which will rename all ".txt" file to ".pip"

Every week or so I receive some text files which I need to change the extensions for before putting through some software. I previously wrote a vba script which would do the renaming for me, but our IT team in their infinite wisdom have decided to block all vba scripts and will not unblock them.

I have attempted to find some batch script online which will rename the file extensions however the problem is:

1) I cannot figure out how to rename all files in the same folder as the batch file
2) The script fails with the error "UNC paths are not supported for current directory"

Can anyone please help me put something together?

Many thanks


See More: Batch Script to rename file extensions

Report •

August 16, 2016 at 03:51:16
:: It might help to post the script which gives the error.
:: Or it might not.
::====== script starts here ===============
:: always.bat 2016-08-16 17:45:09.67
@echo off & setLocal enableDELAYedeXpansioN

for /f "tokens=* delims= " %%a in ('dir/b *.txt') do (
echo ren "%%a" "%%~Na.php"
goto :eof
::====== script ends here =================


M2 Get custom script or take private lessons

Report •

August 16, 2016 at 04:46:14
Hi Mechanix2Go,

Thank you very much, this worked perfectly when run from a memory stick, but when I run it from the folder in which I have all my files, on our network share


I get the error


CMD.exe was started with the above path as the current directory. UNC paths are not supported.  Defaulting to Windows directory.
Access is denied.

I guess this means I cant run this commend with a UNC path as the current directory? Access denied probably because us users don't have access rights to the c:\ drive.

However this shouldn't be a problem I can just copy the files to a external hard drive, do the rename then copy them back.

My friend you are a legend thank you very much for you help I really appreciate it.

Report •

August 16, 2016 at 05:33:09
✔ Best Answer
Could try this bit of untested code:
ren "%~dp0\*.txt" *.pip

How To Ask Questions The Smart Way

Report •

Related Solutions

August 16, 2016 at 05:44:28

that worked beautifully!!! thanks you both. This now works with UNC paths. I looked online and was trying to use Pushd very unsuccessfully, but your code nailed it perfectly.

Thanks guys this will save me so much time!!

really appreciate your help.


Report •

Ask Question