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.
Read File name/FTP Commands
Moderators: JRL, Dorian (MJT support)
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%
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
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
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!
Bob
A humble man and PROUD of it!
Using the right function to parse a filename from a string
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]
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]