How can I parse FTP log file lines into another format

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
authorleon
Posts: 3
Joined: 11 Apr 2015 17:26

How can I parse FTP log file lines into another format

#1 Post by authorleon » 11 Apr 2015 17:31

I really need some help here. I have been racking my brain for about 2 weeks.

I use ftp.exe with the ls command, however is does not export FULL paths. The text file looks likes this:

Code: Select all

/var/www/xxx/video_folder_1:
New folder
New folder - Copy
New folder - Copy (10)
New folder - Copy (10) - Copy
New folder - Copy (10) - Copy - Copy
New folder - Copy (11)

/var/www/xxx/video_folder_2:
cideo.mp4
sadasd


However I need it to look like this.

Code: Select all

/var/www/xxx/video_folder_1/New folder
/var/www/xxx/video_folder_1/New folder - Copy
/var/www/xxx/video_folder_1/New folder - Copy (10)
/var/www/xxx/video_folder_1/New folder - Copy (10) - Copy
/var/www/xxx/video_folder_1/New folder - Copy (10) - Copy - Copy
/var/www/xxx/video_folder_1/New folder - Copy (11)/
/var/www/xxx/video_folder_2/cideo.mp4
/var/www/xxx/video_folder_2/sadasd


Anyone please

Thank you.

PS. Is anyone know of a command that outputs the full path with ftp.exe. Please let me know as the above would not be needed.
Last edited by authorleon on 11 Apr 2015 17:57, edited 1 time in total.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Is this even possible

#2 Post by Squashman » 11 Apr 2015 17:42

This is a list of all the commands you can run.
http://ss64.com/nt/ftp.html

authorleon
Posts: 3
Joined: 11 Apr 2015 17:26

Re: Is this even possible

#3 Post by authorleon » 11 Apr 2015 17:51

Hello,


Yes. I have looked but I could not find anything. I am not an expert but I cannot find a solution for this.

Thanks

authorleon
Posts: 3
Joined: 11 Apr 2015 17:26

Re: Is this even possible

#4 Post by authorleon » 11 Apr 2015 19:04

Squashman wrote:This is a list of all the commands you can run.
http://ss64.com/nt/ftp.html



Solution:

Code: Select all

echo off
setlocal EnableDelayedExpansion

for /F "delims=" %%a in (test.txt) do (
   set "line=%%a"
   if "!line:~0,1!" equ "/" (
      set "header=%%a"
   ) else (
      echo !header:~0,-1!/%%a
   )
)


Thanks to http://stackoverflow.com/questions/2958 ... 3#29584553

Credit where credit is due :)

Post Reply