Read File name/FTP Commands

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
jeffmazerski
Newbie
Posts: 4
Joined: Wed Apr 07, 2010 2:56 pm

Read File name/FTP Commands

Post by jeffmazerski » Wed Apr 14, 2010 12:40 pm

Here is my problem. I need to retrieve a file from an FTP server. The name of this file will change daily. I can read and get the contents of the specific folder with various ftp script commands. Todays file may be something like XXX20100414.csv. When I use the READFILE command, I can get the specific file into a variable into my script. However there are other values in the variable. This is what my variable looks like from the READFILE command.

-rw-r----- 1 57223 6560 148 Apr 12 15:13 XXX20100414.csv

the format and file name will basically be the same each day. so the file name will never exceed X number of characters and will always be a csv file. How can I trim the first 50 characters off of the variable so i am just left with the XXX20100414.csv in my variable name??? Once I have the file name in a variable, I can do a few rename or FTP commands to get my file off of the FTP site.

Any help or suggestions is appreciated. If someone has a better or easier way to do what I am trying to do, I'm open to suggestions.

User avatar
JRL
Automation Wizard
Posts: 3505
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed Apr 14, 2010 12:52 pm

Assuming your file name will NEVER have spaces in it. You could use the Separate> function and divide up the string by spaces. Then set your variable to the last space separated value which will be your file name.

Code: Select all

Let>var=-rw-r----- 1 57223 6560 148 Apr 12 15:13 XXX20100414.csv
Separate>var, ,part
Let>var=part_%part_count%

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Wed Apr 14, 2010 3:19 pm

Could also use RegEx to capture everything after the last space char.
Don't have access to Macro Scheduler right now, so syntax may not be quite correct, but the search pattern could look something like this:

Let>vNeedle=^.* (X{3}[0-9]{8}.csv)$
Let>vHaystack=-rw-r----- 1 57223 6560 148 Apr 12 15:13 XXX20100414.csv
RegEx>%vNeedle%,%vHaystack%...........

And $1 would be the filename
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Using the right function to parse a filename from a string

Post by adroege » Fri May 14, 2010 1:09 pm

If as you say, the file name is always the same number of characters,
then here is possibly a simpler approach.


[code]
VBStart
VBEnd

Let>var=-rw-r----- 1 57223 6560 148 Apr 12 15:13 XXX20100414.csv

VBEval>right("%var%",15),result
MessageModal>result
[/code]

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts