Computer Hope
Microsoft => Microsoft DOS => Topic started 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
???
-
yes - 2 ways
1]
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
-
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
-
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
-
Hi,
Here it is
@echo off
RENAME C:\Aa\Test\ *.xml *.sst
Thanks
-
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"
-
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
-
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