I'd like to write a batch file that called "listfiles.bat" which takes an optional parameter for a filter to list files. So, if a parameter is passed, I want my batchfile to do a dir "*parameter*.*." If no parameter is passed, I want my batchfile to do a "dir *.*"
Another variant to my problem is that I will call listfiles.bat from an utility called SlickRun. SlickRun sends a "$w$" as the default parameter. Therefore, inside listfiles.bat, I would like to reset the incoming parameter to a "".
This is what I have. Could you please correct this to achieve the above outcome?
Thank you so much.
-Nina
---------------------------------------------------
if "%1" == "$w$" then
"%1" = ""
if "%1" == "" goto skip1
dir *"%1"*.* /b > file.txt
goto skip2
:skip1
dir *.* /b > file.txt
:skip2
{do other things}
---------------------------------------------------
Resetting the incoming parameter in a batch file
Moderator: DosItHelp
Re: Resetting the incoming parameter in a batch file
IF slick run is always sending a $w$ to your batch file then you could use the SHIFT command to get ride of the initial $w$.
Re: Resetting the incoming parameter in a batch file
OK. How do I incorporate the SHIFT command in my little batch file using an "IF" statement. In other words, what would my batch file in the OP look like?
Thanks very much,
-Nina
Thanks very much,
-Nina
Re: Resetting the incoming parameter in a batch file
That's a good idea Squashman.
This is untested:
This is untested:
Code: Select all
@echo off
if /i "%~1"=="$w$" shift
if "%~1"=="" (
dir /b
) else (
dir "*%~1*.*" /b
)