Resetting the incoming parameter in a batch file
Posted: 22 Mar 2012 05:52
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}
---------------------------------------------------
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}
---------------------------------------------------