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

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.

Batch file append

Reply to Message Icon

Name: sajjadr21
Date: November 21, 2003 at 05:27:57 Pacific
OS: XP
CPU/Ram: 504 MB
Comment:

hi all,

following batch file creates the list of directory stucture on dirlist.txt. I just want to add some text.
Kindly help!


desired output file
-------------------

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="multiple_input3.xsl"?>

<someURIs>
<file>C:\kix\Enterprise031114\Enterprise\file.xml</file>
<file>C:\kix\Enterprise031114\Enterprise\AFC\file.xml</file>
<file>C:\kix\Enterprise031114\Enterprise\AHAW\file.xml</file>
</someURIs>

dirlist.txt
-----------
C:\kix\Enterprise031114\Enterprise
C:\kix\Enterprise031114\Enterprise\AFC
C:\kix\Enterprise031114\Enterprise\AHAW

batch file:
-----------

@echo off
set topdir=C:\kix\Enterprise031114\Enterprise
set tempdir=C:\temp
set file2copy=C:\tree.xsl
set look4file=xmlinterlinks.xml

echo %topdir%> "%tempdir%\dirlist.txt"
dir "%topdir%" /s /b /ad >> "%tempdir%\dirlist.xml"

for /F "delims=*" %%p IN (%tempdir%\dirlist.txt) do if exist "%%p\%look4file%" copy "%file2copy%" "%%p"



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: November 21, 2003 at 07:15:30 Pacific
Reply:

Below you find the script that converts your text list into a html one; use iit in your batch by calling

Call Lst2Xml DirList.txt DirList.htm

or embed directly in your script.

The trick is straightforward: prefix the forbidden character with a ^ (caret) to strip away its special meaning and use it then as an usual alphameric one.

--- Lst2Xml.bat -----

@Echo Off

:: LST2XML.BAT Syntax: Lst2Xml File_In File_Out

Echo ^<?xml version="1.0" encoding="ISO-8859-1"?^>> %~f2
Echo ^<?xml-stylesheet type="text/xsl" href="multiple_input3.xsl"?^>>> %~f2

Echo ^<someURIs^>>> %~f2
For /F "tokens=*" %%A in (%~f1) Do Echo ^<file^>%%A\file.xml^</file^>>> %~f2
Echo ^</someURIs^>>> %~f2


0

Response Number 2
Name: sajjadr21
Date: November 21, 2003 at 07:43:15 Pacific
Reply:

Thanks IVO for the response. I added it in my batch file but i get the error message
Error
-----
The file name, directory name, or volume label syntax is incorrect

Please look at the complete file which is as following

@echo off
set topdir=C:\kix\Enterprise0311141\Enterprise
set tempdir=C:\temp
set file2copy=C:\tree.xsl
set look4file=xmlinterlinks.xml


echo %topdir%> "%tempdir%\dirlist.txt"
dir "%topdir%" /s /b /ad >> "%tempdir%\dirlist.txt"

for /F "delims=*" %%p IN (%tempdir%\dirlist.txt) do if exist "%%p\%look4file%" "<file>%%p</file>" > "%tempdir%\dirlist1.txt"

call read_text c:\temp\dirlist.txt dirlist.htm

rem read_text is the bat file IVO wrote


0

Response Number 3
Name: IVO
Date: November 21, 2003 at 08:09:02 Pacific
Reply:

Your flaw is

"<file>%%p</file>"

"^<file^>%%p^</file^>"

remember: prefix with ^ (caret) to have the character interpreted as its own and NOT as a special meaning symbol (redirector in that case)


0

Response Number 4
Name: IVO
Date: November 21, 2003 at 12:29:08 Pacific
Reply:

I am looking again at your script more accurately and I confirm the integrity of my batch (I tested it again and it performed fine); the string in your For statement I brought to your attention in my previous post is still marked as bad, but more *the whole statement following the If clause* is questionable (either coded fine) as it seems meaningless: have you forgotten an Echo command?


0

Response Number 5
Name: sajjadr21
Date: November 24, 2003 at 02:23:12 Pacific
Reply:

yes, you are right ... i was making a mistake in writing the path. thanks!

is it possible that it replaces & with & if it finds in path name?


0

Related Posts

See More



Response Number 6
Name: IVO
Date: November 24, 2003 at 02:55:45 Pacific
Reply:

Please, post your question in other words, explain it, as I do not understand...

> is it possible that it replaces & with & if it finds in path name?

What do you mean?



0

Response Number 7
Name: sajjadr21
Date: November 24, 2003 at 05:05:53 Pacific
Reply:

i just wanted to replace the text '&' with '&'

I have found the way in faq # 19

thanks for your help IVO !


0

Sponsored Link
Ads by Google
Reply to Message Icon






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: Batch file append

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

User log in date from a batch file www.computing.net/answers/dos/user-log-in-date-from-a-batch-file/7783.html

New line in a batch file www.computing.net/answers/dos/new-line-in-a-batch-file/4750.html