Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello.
I have a directory listing in a text done with /B switch so I get one filename.
Is there an easy way to take this filename and add a couple of switches and then run as batch file; I keep getting the added switches on the next line.
I would like the line to be:
sdat4285.exe /SILENT /F
*****************************************
dir c:\temp\sdat*.exe /B > c:\temp\dirsdat.txt
echo /SILENT /F>> c:\temp\dirsdat.txt
copy c:\temp\dirsdat.txt c:\temp\runsdat.bat
call c:\temp\runsdat.batThanks in advance.
Geoff

The problem is that along with the string of characters, that is, the filename itself, two characters more go to the file - the CR/LF characters, which in that order represent a line break. So, when you append more data to the file, it appers on the next line, because of the line break.
Here's a work around:
dir c:\temp\sdat*.exe /B > c:\temp\dirsdat.txt
copy c:\temp\dirsdat.txt c:\temp\runsdat.bat
echo e0 49 49> %temp%.\$
echo g=0 2 >> %temp%.\$
for %%? in (w q) do echo %%?>> %temp%.\$
DEBUG c:\temp\runsdat.bat < %temp%.\$ > nul
del %temp%.\$
echo /SILENT /F>> c:\temp\runsdat.bat
call c:\temp\runsdat.batThat script uses a debug script to delete the two last characters from the file with the filename, eliminating the line break, Then, the string appended "/SILENT /F" will go to right after the filename.
Here's another method, which has a more wide use:
echo e100'SET %%1='> %temp%.\$.bat
for %%? in (rcx 7 w q) do echo %%?>> %temp%.\$.bat
type %temp%.\$.bat |DEBUG %temp%.\$.bat > nul
dir c:\temp\sdat*.exe /B >> %temp%.\$.bat
call %temp%.\$.bat MyFilename
echo %MyFilename% /SILENT /F> %temp%.\$.bat
call %temp%.\$.bat
del %temp%.\$.batThat batch file uses a debug script to create a file with the string "SET %1=" and without a final CR/LF, that is, any data appended to it will go straight to right after the "=" sign. Then, the DIR ouput is appended to such file, and it is executed with the parameter "MyFilename". So, it sets the variable %MyFilename% with the filename. After that, you can use the variable to create the batch file with the parameters "/SILENT /F" (that's being done on the third line from bottom to top).
-- Leonardo Pignataro - Secret_Doom --
secret_doom@hotmail.com
www.batch.hpg.com.br____________________________________________________

Thanks very much- you are a genius with this stuff!
1) Just wondering what does the period in "%temp%.\" do?
2) There is no space after the "sdat4285.exe" and before "/silent /F" not sure if it matters or not but may in other expressions..is there a way to add a space?
Thanks in advance.

> 1) Just wondering what does the period
> in "%temp%.\" do?That period is in case:
a) The %temp% variable ends with a slash. c:\temp\.\filename is a valid path, but c:\temp\\filename is not, when regarding DOS and Win9x.
b) The %temp% variable is empty. ".\filename" represents a file on the current directory, while "\filename" represents a file on the root. Accidentaly overwriting a file from the root would probably be worst than most other files.
Such cases are rare, and in all my scripts which use the %temp% variable I assume it is assigned to a valid and writeable path, specific for temporary files (and therefor spendable), but taking that security measure won't hurt. It's a good writing habit.
> 2) There is no space after the
> "sdat4285.exe" and before "/silent /F"
> not sure if it matters or not but may in
> other expressions..is there a way to add
> a space?I assume you're talking about the first method I posted (the second does include a space). Generally, you can specify switches to .exe files without a space, but it can be added. Change the second line from bottom to top by this:
echo. /SILENT /F>> c:\temp\runsdat.bat
That dot could be a space, by the way. But the space couldn't be a dot, though.
-- Leonardo Pignataro - Secret_Doom --
secret_doom@hotmail.com
www.batch.hpg.com.br_____________________________________________

![]() |
![]() |
![]() |

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