How to get the file name ?

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
kennie_n2000
Newbie
Posts: 4
Joined: Thu Feb 01, 2007 6:25 pm

How to get the file name ?

Post by kennie_n2000 » Tue Oct 30, 2007 6:46 pm

I need help
If I coded
GetFileList>E:\test\*.txt,files
Separate>Files,;,file_names
bla bla


I will the whole path included the file name
example: file_names = E:\test\testfile1.txt
which is i dont need the whole path

I need to get the file only >> testfile1.txt

thanks

User avatar
pgriffin
Automation Wizard
Posts: 460
Joined: Wed Apr 06, 2005 5:56 pm
Location: US and Europe

Post by pgriffin » Tue Oct 30, 2007 7:16 pm

There are many different ways to strip off the path from the file name. Here is one example.

Code: Select all

let>FileAndPath=C:\Folder\Folder\MyFile.txt
sep>%FileAndPath%,\,seg
let>max=seg_count
pos>.,seg_%max%,1,vDot
if>vDot>0
     sep>seg_%max%,.,fseg
     let>FileExt=fseg_2
     let>TheFile=%fseg_1%.%FileExt%
else
     let>TheFile=%fseg_1%
endif

mdl>the file is %TheFile%


This example works with the typical path and file...c:\folder\folder\MyFile.txt

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Tue Oct 30, 2007 9:53 pm

Or another approach that doesn't care about the filename format:

Code: Select all

Let>mydir=c:\temp\
GetFileList>%mydir%*.*,files
StringReplace>files,%mydir%,,files2
Separate>files2,;,file_names
MessageModal>Num Files: %file_names_count%
Let>k=0
Repeat>k
Let>k=k+1
MessageModal>file_names_%k%
Until>k,file_names_count

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