I am writing a batch script that uses Windows ftp client to connect to our FTP server and does a directory listing and outputs it to a file. The output is very dirty though, so I then do a FINDSTR on the file to get only the lines I am interested in, and then a FOR loop on that to get the cleanest version I can in order to output to screen (displays a summary of the files that are on the server).
The problem is that the FTP server runs on Linux, and at the end of each file (the return of the dir command) it puts a CR.
Now this plays havock with my TOUCH command which tries to display the clean output after the for loop. It doesn't like the CR at all and messes everything up!.
Here is what the text file looks like:
And here is what TOUCH displays when I call the file:
Here is the text file that is being called (in the script it is CSDIR_ftpdirlist_output.tx
And here is the first FINDSTR code that is run against that file:
FINDSTR "Metro Insights" %TEMP%\CSDIR_ftpdirlist_output.txt > %TEMP%\CSDIR_ftpdirlist_raw.txt
FINDSTR "Regional Insights" %TEMP%\CSDIR_ftpdirlist_output.txt > %TEMP%\CSDIR_ftpdirlist_raw.txt
FINDSTR "National Insights" %TEMP%\CSDIR_ftpdirlist_output.txt > %TEMP%\CSDIR_ftpdirlist_raw.txt
And the second peice of code, which results in the first picture:
ECHO The current files for today are: > %TEMP%\CSDIR_ftpdirlist.txt
FOR /F "tokens=1-11" %%G IN (%TEMP%\CSDIR_ftpdirlist_raw.txt) DO @echo %%O %%P created on %%L %%M at %%N >> %TEMP%\CSDIR_ftpdirlist.txt
I know there are third party tools I can use to do this, but if possible I would like to keep everything to one batch file and without having to call any other executables.
So if there is any way I can strip that CR from the last clean file, well that'd be perfect!