Opening a File with Wildcard

Ideas for new features & functions

Moderators: Dorian (MJT support), JRL

Post Reply
ADP_MAN
Junior Coder
Posts: 45
Joined: Wed Apr 07, 2004 2:04 pm

Opening a File with Wildcard

Post by ADP_MAN » Wed Sep 10, 2008 8:29 pm

I have a file that needs to be opened and renamed on a daily basis. PART of the filename changes daily so I want to open the file using the "*". Here is part of the script I have so far:


I first want to locate the file and see if the file is there. In this case the file name is "ETCTXT02292295P.091008.024310001.txt" The first part of the file name does not change "ETCTXT02292295P." and the second part is the date. The final part of the file name changes daily and it's not something I can determine. When I run IfFileExists using the formula below, it will correctly tell me if the file exists or not. After that is complete I want to open the file and that is where I'm having problems. Any suggestions?

Day>theDay
Month>theMonth
Year>theYear
//GET LAST TWO DIGITS OF YEAR
MidStr>theYear,3,2,theYear

//DETERMINE YEAR
ifFileExists>T:\IQ\DATA\COMM\outbound\outbound\ETCTXT02292295P.%theMonth%%theDay%%theYear%*,Open

Label>Open
ExecuteFile>T:\IQ\DATA\COMM\outbound\outbound\ETCTXT02292295P.%theMonth%%theDay%08*

Thanks in advance,
Dominic

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Sep 10, 2008 8:41 pm

You should use GetFileList to retrieve a list of matching files (which by your email I assume would contain just one file). Loop through the returned list to get each FULL filename. Then you can open it.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

ADP_MAN
Junior Coder
Posts: 45
Joined: Wed Apr 07, 2004 2:04 pm

Post by ADP_MAN » Wed Sep 10, 2008 9:18 pm

Thanks for the quick reply!

I would like to first make sure the file exists, then open it (there could be 5+ files in the folder, but only one with that filename). After this is found I would like to open it, rename it then close it. Obviously this should be fully automated.

I'm not sure I follow what you are saying by retrieving the list of file names. If I run GetFileList on that folder, would it manually generate the list or would it just be in memory? What command would I use to open the one I'm looking for?

Sorry - I'm still a bit confused.

Thanks,
Dom

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

Post by JRL » Wed Sep 10, 2008 10:46 pm

From Help for GetFileList>
GetFileList>filespec,result[,delimiter]

GetFileList returns a list of the files found matching the specified filespec. For instance, to return the list of files in the temp directory specify c:\temp\*.* as the filespec.

If delimiter is ommitted each filename is separated by a semicolon (;). Otherwise the filenames are separated by the delimiter specified.
The results of GetFileList are stored in a variable. That variable's contents can be searched using the Position> function to determine if a given string (your file name) is contained in the contents. Once the position is found Midstr> and Separate> can be used to isolate the file from the rest of the list.

Try something like this:

Code: Select all

Day>theDay
Month>theMonth
Year>theYear
//GET LAST TWO DIGITS OF YEAR
MidStr>theYear,3,2,theYear

//DETERMINE YEAR
GetFileList>T:\IQ\DATA\COMM\outbound\outbound\*.txt,filelist
Let>filename=ETCTXT02292295P.%theMonth%%theDay%%theYear%
Position>%filename%,%filelist%,1,pos
Midstr>filelist,pos,1000000,filetest
separate>filetest,;,file

ExecuteFile>T:\IQ\DATA\COMM\outbound\outbound\%file_1%


ADP_MAN
Junior Coder
Posts: 45
Joined: Wed Apr 07, 2004 2:04 pm

Post by ADP_MAN » Thu Sep 11, 2008 2:19 pm

I'll give this a shot - thanks so much for your help!

DR

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