CopyFile using Variable

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

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

CopyFile using Variable

Post by ADP_MAN » Wed May 06, 2015 7:01 pm

Hi All,

I understand that if you try to find a file by using a wildcard, you will be unable to move and rename the file. For example, I have a file named "CITI_MT940_201505050710.SNL18240D11430824221593539S". When it loads into a specific folder, I would like to copy it, rename, and place it in a different folder. I am only searching the folder for "CITI_MT940*.*" because the rest of the file name changes daily. When I run the code below, the file is copied but instead of just the file moving (and renamed) a new folder is created named "CITI_20150506.rpt"

Day>Day
Month>Month
Year>Year
Let>todayDate=%Year%%Month%%Day%

Label>CITI
IfFileExists>C:\Temp\CITI_MT940*.*
Let>tempFile=C:\Temp\CITI_MT940*.*
Let>CITI=C:\Temp\CITI_%todayDate%.rpt
CopyFile>tempFile,CITI
Goto>End
Else
Wait>5
MessageModal>Not Here
Goto>CITI
Endif

What script would you write to move and rename File 1 into File 2?

File 1
C:\Temp\CITI_MT940_201505050710.SNL18240D11430824221593539S

File 2
C:\Temp\NewFolder\CITI_20150505.rpt

A Big thank you in advance!

DJR

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

Re: CopyFile using Variable

Post by Marcus Tettmar » Thu May 07, 2015 9:39 am

Hi,

Not sure why it would create a new folder.

But to Move or Rename a file use the MoveFile or RenameFile functions.

Also - be careful - you have a variable AND a label called CITI - that could get confusing. The label CITI will take the value of the variable.
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

Re: CopyFile using Variable

Post by ADP_MAN » Thu May 07, 2015 1:51 pm

Hi Marcus,

I don't think I'm explaining it correctly. Say I want to do something simple like this:

RenameFile>C:\Temp\CITI_MT940*.*,C:\Temp\CITI.rpt
Goto>End


Nothing happens. From my research, I believe the error is due to the fact that I'm using a variable *.* in my original file search. The file name changes daily, so I can't grab the actual file name. When I use "CopyFile" it creates that "new" folder and places the file in it. I think I need to be able to grab a file name and send it to a variable. If I can somehow manage that it should help my program.

Thanks,
Dom

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

Re: CopyFile using Variable

Post by Marcus Tettmar » Thu May 07, 2015 2:22 pm

That's correct - you're asking it to copy multiple files (potentially) to one. Hence it wants to copy to a folder.

Instead, use GetFileList to get a list of files matching that file spec and then loop through ....

Code: Select all

GetFileList>c:\temp\CITI_MT940*.*,files
Separate>files,;,file_names
If>file_names_count>0 
  Let>k=0
  Repeat>k
    Let>k=k+1
    Let>this_file=file_names_%k%
    CopyFile>this_file,c:\temp\CITI.rpt
  Until>k,file_names_count
Endif
However, this also doesn't really make much sense since if there is more than one match they are going to keep overwriting.

Perhaps you only want to move the first match (file_names_1) ?

Code: Select all

GetFileList>c:\temp\CITI_MT940*.*,files
Separate>files,;,file_names
If>file_names_count>0 
  CopyFile>file_names_1,c:\temp\CITI.rpt
Endif
??
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

Re: CopyFile using Variable

Post by ADP_MAN » Thu May 07, 2015 3:50 pm

I'm still having issues.

If I had a single file in a folder:

c:\Temp\Temp\CITI_MT940_87609876.SNL09870939

and wanted to rename and move it to "CITI.rpt" here:

c:\Temp\CITI.rpt

How would I do this. I tried your code (using the debugger) but having difficulty getting anything to show up in that folder.

Thanks.
Dom

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

Re: CopyFile using Variable

Post by Marcus Tettmar » Thu May 07, 2015 4:56 pm

This works for me:

Code: Select all

GetFileList>c:\temp\temp\CITI_MT940*.*,fileList
Separate>fileList,;,files
If>files_count>0
  CopyFile>files_1,c:\temp\citi.rpt
Endif
See my screencast showing this working:
http://vids.mjtnet.com/watch/cohiDNfhHZ
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

Re: CopyFile using Variable

Post by ADP_MAN » Thu May 07, 2015 5:43 pm

Marcus - it worked! Thanks for the video. I realized what I was doing wrong and made the adjustment.

Regards,
Dom

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