[SOLVED] parse COMPLETE line from a file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
vikisch
Posts: 2
Joined: 28 Oct 2013 16:17

[SOLVED] parse COMPLETE line from a file

#1 Post by vikisch » 28 Oct 2013 16:37

I would like to write a batch-script to backup my junction and symbolic links
I'm using this command:

Code: Select all

dir "%CD%" / al / s>out.txt

In the out.txt-file are for example the following lines:
26/11/2013 12:34 <JUNCTION> FolderJunction1 [C:\Path1\SubFolder1]
26/11/2013 23:44 <SYMLINKD> FolderSymlink2 [C:\Path2\SubFolder2]


If I parse this above quoted line(s) with the following command..

Code: Select all

for / f "tokens = *" %%a in (out.txt) do call :FurtherProcessing %%a

I get the following output for %%a
26/11/2013 12:34 FolderJunction1 [C:\Path1\SubFolder1]
26/11/2013 23:44 FolderSymlink2 [C:\Path2\SubFolder2]


How do I get the complete original line, or what I'm doing wrong?
I'm missing the information if the line is from a <JUNCTION> or <SYMLINKD>!
Last edited by vikisch on 29 Oct 2013 16:42, edited 1 time in total.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: parse COMPLETE line from a file

#2 Post by foxidrive » 28 Oct 2013 17:24

You have spaces all through your code which will cause it all to fail.

Copy and paste your code and perhaps it will be clearer.

aGerman
Expert
Posts: 4743
Joined: 22 Jan 2010 18:01
Location: Germany

Re: parse COMPLETE line from a file

#3 Post by aGerman » 28 Oct 2013 17:33

< and> are symbols for redirections. You're lucky if you get any output and if you don't create some zero files.
Actually I would process the output of DIR directly in a FOR /F loop. Since I don't know your whole code I don't know if that would be the best way in your case ...

Anyway, if you want to work in a subroutine don't pass such a string as an argument but assign a variable instead. Use the delayed variable expansion inside of your subroutine for a rather safe processing.

Code: Select all

...
for /f "delims=" %%a in (out.txt) do (set "line=%%a" &call :FurtherProcessing)
...
goto :eof

:FurtherProcessing
setlocal EnableDelayedExpansion
echo !line!
endlocal
goto :eof

Regards
aGerman

vikisch
Posts: 2
Joined: 28 Oct 2013 16:17

Re: parse COMPLETE line from a file

#4 Post by vikisch » 29 Oct 2013 16:06

here is my code without wrong whitespace

Code: Select all

for /f "tokens=*" %%a in (out.txt) do call :FurtherProcessing %%a


but the tip of aGerman has already helped me - thank you a lot. Problem solved!

Post Reply