Computing.Net > Forums > Disk Operating System > append a file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

append a file

Reply to Message Icon

Name: geoff green
Date: August 13, 2003 at 12:12:43 Pacific
OS: Win9x
CPU/Ram: PII/ 256
Comment:

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.bat

Thanks in advance.

Geoff



Sponsored Link
Ads by Google

Response Number 1
Name: Secret_Doom
Date: August 13, 2003 at 19:06:01 Pacific
Reply:

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.bat

That 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%.\$.bat

That 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

____________________________________________________


0

Response Number 2
Name: geoff green
Date: August 13, 2003 at 19:54:32 Pacific
Reply:

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.


0

Response Number 3
Name: Secret_Doom
Date: August 13, 2003 at 21:05:29 Pacific
Reply:

> 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

_____________________________________________


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: append a file

Creating a batch file to append to a text file www.computing.net/answers/dos/creating-a-batch-file-to-append-to-a-text-file/3180.html

How do I write directly to a file in DOS? www.computing.net/answers/dos/how-do-i-write-directly-to-a-file-in-dos/2394.html

Set number of lines from a file to a var www.computing.net/answers/dos/set-number-of-lines-from-a-file-to-a-var/6487.html