Adding manifest list for weekly FTP files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
snake9284
Posts: 4
Joined: 18 Apr 2014 15:47

Adding manifest list for weekly FTP files

#1 Post by snake9284 » 18 Apr 2014 15:57

Good afternoon. I have an FTP task set up that transmits a number of files to a vendor but the Service Delivery team is requesting that I create a manifest file to send along with the data files. Is it possible to scan a file for the number or rows and output the results to a file? What I'm picturing in a single manifest file like weekly_ftp.mft that would contain something like

filename1 900000 rows 153000 Kb
filename2 90000 rows 96000 Kb
filename3 1000 rows 10000 Kb

Any guidance would be greatly appreciated.

Frank

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

Re: Script Help Request

#2 Post by Squashman » 18 Apr 2014 17:55

I assume these are text files.
Are they fixed length text files or are they delimited?

snake9284
Posts: 4
Joined: 18 Apr 2014 15:47

Re: Script Help Request

#3 Post by snake9284 » 18 Apr 2014 18:08

That is correct. They are | pipe delimited text files with .dat as the extension. Sample data from one of the files looks like this:
20|000042|D|000
20|000082|Y|100
20|000103|D|000
20|000120|M|000
20|000123|M|000
20|000124|M|000
20|000205|Y|100
20|000225|D|000
20|000317|M|000
20|000473|D|000
20|000501|M|100
20|000510|D|000
20|000519|D|000
20|000543|D|000

But they all have different numbers of columns. Each line is ended with {CR}{LF}

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

Re: Script Help Request

#4 Post by foxidrive » 18 Apr 2014 20:13

Depending on how your FTP script accepts the filenames then it can include a subroutine like this: (untested)

Code: Select all

:manifest_list
for %%a in ("%~1") do (
   for /f %%b in (' find /c /v "" ^< "%%a" ') do >>"weekly_ftp.mft" echo %%~nxa - %%b - %%~za
)
goto :EOF



Calll it like this:

Code: Select all

call :manifest_list "filename.dat"

snake9284
Posts: 4
Joined: 18 Apr 2014 15:47

Re: Adding manifest list for weekly FTP files

#5 Post by snake9284 » 21 Apr 2014 15:25

Thanks foxidrive but I'm not sure how to implement this code. Do I save it as a .bat file in the c: drive? Thanks for your help with this.

Code: Select all

:manifest_list
for %%a in ("%~1") do (
   for /f %%b in (' find /c /v "" ^< "%%a" ') do >>"weekly_ftp.mft" echo %%~nxa - %%b - %%~za
)
goto :EOF

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

Re: Adding manifest list for weekly FTP files

#6 Post by Squashman » 21 Apr 2014 18:45

You can put into your existing BATCH file like a function.

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

Re: Adding manifest list for weekly FTP files

#7 Post by foxidrive » 22 Apr 2014 09:59

Here's another way to use it.

Create a batch file with this and name it manifest_list.bat and place it in the folder with the dat files and FTP batch file or in a folder that is on the path.

Code: Select all

@echo off
:manifest_list.bat
for %%a in ("%~1") do (
   for /f %%b in (' find /c /v "" ^< "%%a" ') do >>"weekly_ftp.mft" echo %%~nxa - %%b - %%~za
)
goto :EOF


Then in your batch file you can use a line like this assuming your file is called filename.dat

call manifest_list.bat "c:\storage\folder\filename.dat"

or like this if they are in the same folder:

call manifest_list.bat "filename.dat"

snake9284
Posts: 4
Joined: 18 Apr 2014 15:47

Re: Adding manifest list for weekly FTP files

#8 Post by snake9284 » 22 Apr 2014 10:50

Thanks again foxidrive. I created the .bat file as suggested and added the following to the beginning of the FTP .bat file. Thanks again for your help, this was a much quicker solution than I had hoped for!

Code: Select all

Cd c:\
echo filename - rows - filesize > weekly_ftp.mft
Call manifest_list.bat "e:\transfer\file1.dat"
Call manifest_list.bat "e:\transfer\file2.dat"
Call manifest_list.bat "e:\transfer\file3.dat"
Call manifest_list.bat "e:\transfer\file4.dat"


Frank

Post Reply