Solved Batch: Extract file sized from ftp dir output

May 27, 2011 at 11:54:55
Specs: Windows 2003
I need to extract the size of a file from an ftp directory listing. I am able to log the ftp output to a text and can pass on the entire string containing the file which I need the size of but I'm having trouble parsing the whole string because length and position of the string differs.

-rw-rw-r-- 1 555 1007 247036 May 27 17:15 Transactions_Asia.zip
-rw-rw-r-- 1 555 1007 37 May 27 17:15 Transactions_Europe.zip
-rw-rw-r-- 1 555 1007 1607724 May 27 17:16 Transactions_NorthAmerica.zip

I use findstr to find the specific file I need and what I get is something like below:
ftp.log:-rw-rw-r-- 1 555 1007 1607724 May 27 17:16 Transactions_Asia.zip
and what I only need is the file size which is 1607724


See More: Batch: Extract file sized from ftp dir output

Report •


#1
May 27, 2011 at 23:29:21
✔ Best Answer
i think file size always comes to 7th position.. try this one


for /f "tokens=6 delims=- " %a in ('findstr /i "filename" input_text_string.txt') do echo %a

i m using - and space as delim and saved your ftp log as input text string

Subhash Chandra.
http://www.wintechgeek.com


Report •

#2
May 30, 2011 at 08:17:49
Thanks! I was also able to do it after a while with the following:

for /f "tokens=5 delims= " %%b in ("%filesize%") do set fsize=%%b


Report •
Related Solutions


Ask Question