Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I want to use a command line parameter to fill in the "FILENAME_HERE" section of the following batch file code (see below). I tried using %3 , but it didn't work. Thanks in advance.
@Echo Off
For %%A in (%~f1\xx1cxt00xx*.txt) Do Call :REN %~f1 %%A
GoTo :EOF
:REN
Set File=%~nx2
Ren %~f1\%File% FILENAME_HERE%File:~10%
GoTo :EOF

@Echo Off
Set FileName=%2
For %%A in (%~f1\xx1cxt00xx*.txt) Do Call :REN %~f1 %%AGoTo :EOF
:REN
Set File=%~nx2
Ren %~f1\%File% %FileName%%File:~10%
GoTo :EOFWhere MyBatch File FileName

Thanks Ivo. That works perfectly.
Right now the source directory is passed in as an arguement, is there a way to "hard code" the directory into this program? By the way, the source directory I'm hoping to use is going to have spaces.

@Echo Off
Set Path="My Path with Blanks"
Set FileName=%1
For %%A in (%Path%\xx1cxt00xx*.txt) Do Call :REN %%A
GoTo :EOF:REN
Set File=%~nx1
Ren %Path%\%File% %FileName%%File:~10%
GoTo :EOFWhere now MyBatch FileName and PathName hardcoded in the script and *embraced* by ".

Thanks again!
Just out of curiosity is there a way to set the path (one with spaces) as a command line parameter? Using the old code.

First of all, please replace the Path variable name with e.g. Folder as Path is a system reserved identifier and using it to name a variable may lead to unpredictable side effects. That was my mistake.
Then to get either Folder with spaces and Filename from the command line the easiest way is to change their position on the command tail, i.e.
BatchName FileName "My Path with Spaces"
where Fikename has no blanks and the Path/Folder is embraced by ".
The following script achieves the target
@Echo Off
For /F "tokens=1,*" %%A in ("%*") Do (
Set FolderName=%%B
Set FileName=%%A)For %%A in (%FolderName%\xx1cxt00xx*.txt) Do Call :REN %%A
GoTo :EOF:REN
Set File=%~nx1
Ren %FolderName%\%File% %FileName%%File:~10%
GoTo :EOF

![]() |
Program to check mouse an...
|
PHP E-mail with Styleshee...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |