Computer Hope

Microsoft => Microsoft DOS => Topic started by: zbiebu on February 02, 2010, 08:24:01 AM

Title: Rename multiple files from another folder
Post by: zbiebu on February 02, 2010, 08:24:01 AM
Hi,

I would like to be able to change the file extension on several files at once, but the batch file needs to be in another folder to those files being changed.

For example the files are contained in C:\Aa\temp, and the batch file needs to be in the root of C. The process will be to change the extension from txt to xml, move the files and then change them back to txt. The movement of the files is a separate process and need not be incorporated into a batch file.
Anyone any ideas?

Thanks

 ???
Title: Re: Rename multiple files from another folder
Post by: gpl on February 02, 2010, 08:38:18 AM
yes - 2 ways
1]
Code: [Select]
cd /d C:\Aa\temp
c:\batchfilename
2]
rewrite your batchfile to accept the name of a directory as a parameter and reference your files using the parameter as the path

1] is simplest and it will work on any drive / directory
Title: Re: Rename multiple files from another folder
Post by: zbiebu on February 02, 2010, 09:57:48 AM
Hi,

Thanks for your reply. sorry I'm not sure what you mean about creating a batch file to accept parameters. could you please explain a little further.

Many thanks

Title: Re: Rename multiple files from another folder
Post by: gpl on February 02, 2010, 10:04:57 AM
It would be a lot easier with an example ... could you paste the contents of your batch file and I will show you how to amend it
Title: Re: Rename multiple files from another folder
Post by: zbiebu on February 02, 2010, 10:25:40 AM
Hi,

Here it is

@echo off
RENAME C:\Aa\Test\ *.xml *.sst

Thanks
Title: Re: Rename multiple files from another folder
Post by: gpl on February 02, 2010, 11:10:52 AM
ok then,using your batch, Ill colour code my changes

@echo off
REM %1 is a special variable, the first parameter passed
REM test if any parameter was supplied
If [%1]==[] Goto Error
REM OK, the ~ char in %~1 means strip off the quotes
RENAME "%~1\*.xml" *.sst
GoTo :EOF
REM no param, show error message
:Error
Echo Supply a directory name on the command line, eg
REM %0 is the name of the batchfile as entered on the command line
Echo %0 "My Folder"
Title: Re: Rename multiple files from another folder
Post by: zbiebu on February 03, 2010, 04:26:17 AM
Hi,

Thanks for your reply. I'll give it a try. How would I call the batch and put the variable at the command line?

Thanks
Title: Re: Rename multiple files from another folder
Post by: gpl on February 03, 2010, 04:34:10 AM
Good luck with it
Suppose we called the batchfile RenameXML.bat

then the commandline would be

RenameXML C:\Aa\Test

assuming you were in the root, if not then

C:\RenameXML C:\Aa\Test