OT: MS-DOS batch file question

Hi gang, Does anyone know how I would use a filename contained inside another file in a batch file?

Example:

The file FILE.TXT contains the text NAME.ASC

I want to copy NAME.ASC to somewhere else.

It's been a while.

TIA

Reply to
a7yvm109gf5d1
Loading thread data ...

Use the redirection command typedump.txt, or append ping>>dump.txt. One caveat is you need the FILE.txt to contain all the characters for the command including , so copy may be somewhat of a kluge using a combination of these and a temp file as you build your command list.

Cheers

Reply to
Martin Riddle

messagenews: snipped-for-privacy@e53g2000hsa.googlegroups.com...

ping>>dump.txt.

command including , so copy may be somewhat of

list.

Thanks, but actually it's dead simple, use the FOR command. Who knew? Looks quite handy.

Reply to
a7yvm109gf5d1

To extract a file name from a file, you could use SED. The output of SED would be piped to another batch file. You would then call the new batch file you created from your original batch file to do what you need to do.

SED is an UNIX command line utility which is also compiled as a command line app under Windows. If you are comfortable with regular expressions, then SED is a breeze to use. If you aren't, then it will be unpleasant.

-- Mark

Reply to
qrk

If you can make the FILE.TXT contain SET XYZ=3DNAME.ASC it is a lot easier to do it. You can then copy it and another two files together to make a new batch file. If not, you can still use the trick but with more care

The files:

*** before.txt *** echo this is before the thing ****

*** FILE.TXT *** SET XYZ=3DNAME.ASC

****

*** after.txt *** echo the XYZ got set to %XYZ%

****

*** main.bat *** rem the file you run rem combine them and then run them:

copy before.txt+FILE.TXT+after.txt NewBat.bat

call NewBat.bat

****

if you can't make it a SET then the before.txt need to end with

SET XYZ=3D

and have no carriage return depending on the DOS version, you put a /B into the copy command to force the binary mode.

Reply to
MooseFET

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.