Rename File with partial name

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
giovanniroi
Junior Coder
Posts: 21
Joined: Fri Jul 03, 2009 4:36 pm
Location: Milan,Italy

Rename File with partial name

Post by giovanniroi » Sat Oct 23, 2010 9:28 am

I need to make a macro to rename a file using only a section of the name.
The problem is that the first part of the name change any day and I need to ignore this part and rename the file

I need to do:

RENAME *.0651.TXT , AUDIT.0651.TXT

How can I make this macro?

Thank's for support.
Regards

Giovanni Roi

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

Post by adroege » Sat Oct 23, 2010 4:23 pm

Try this:

Code: Select all

GetFileList>c:\temp\*.txt,files
Separate>files,;,file_names
Let>k=0
Repeat>k
    Let>k=k+1
    Let>myfile=file_names_%k%
    ExtractFilePath>myfile,path_only
    Length>myfile,myLen
    Position>.,myfile,1,nPos,TRUE
    Add>nPos,1
    MidStr>myfile,nPos,myLen,strSub
    RenameFile>myfile,%path_only%\audit.%strSub%
Until>k,file_names_count


giovanniroi
Junior Coder
Posts: 21
Joined: Fri Jul 03, 2009 4:36 pm
Location: Milan,Italy

Thank's for the solution

Post by giovanniroi » Sun Oct 24, 2010 3:27 pm

Thank's for the solution. I modify only the last line of code in:
"RenameFile>myfile, c:\temp\audit.txt,files"

in this case the code work well.

Thank's

Regards

Giovanni Roi

adroege wrote:Try this:

Code: Select all

GetFileList>c:\temp\*.txt,files
Separate>files,;,file_names
Let>k=0
Repeat>k
    Let>k=k+1
    Let>myfile=file_names_%k%
    ExtractFilePath>myfile,path_only
    Length>myfile,myLen
    Position>.,myfile,1,nPos,TRUE
    Add>nPos,1
    MidStr>myfile,nPos,myLen,strSub
    RenameFile>myfile,%path_only%\audit.%strSub%
Until>k,file_names_count


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