简体   繁体   中英

How can I rename file extensions to another extension type, on another directory?

I'm attempting to rename all files with the file extension of ".ACH" to ".TXT" on another directory.

I used the below batch file on my local machine and it works like a charm:

@Echo Off
CD C:\Users\jonsmith\OneDrive\PC\jonsmith-PC\Desktop\TestingBatch Rename
forfiles /S /M *.ACH /C "cmd /c rename @file @fname.TXT"

However, when I attempt to use the same syntax on the server, nothing happens:

@Echo Off
CD D:\AP\ACHTest Rename
forfiles /S /M *.ACH /C "cmd /c rename @file @fname.TXT"

I'm not understanding what I'm doing wrong, but something tells me it's how I'm using the CD command.

I don't want to force Batch, so I have an easier way. Inside file1.ach:

Hello

Inside file2.ach:

Hi

Code:

del file1.ach
del file2.ach

Current directory:

echo Hello >>file1.txt
echo Hi >>file2.txt

Different directory:

echo Hello >>D:\MyWork\TestRename\file1.txt
echo Hi >>D:\MyWork\TestRename\file2.txt

Easy, without forcing anything.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM