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
CopyFile using Variable
Moderators: Dorian (MJT support), JRL
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Re: CopyFile using Variable
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.
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?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Re: CopyFile using Variable
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
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
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Re: CopyFile using Variable
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 ....
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) ?
??
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
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?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Re: CopyFile using Variable
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
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
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Re: CopyFile using Variable
This works for me:
See my screencast showing this working:
http://vids.mjtnet.com/watch/cohiDNfhHZ
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
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?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Re: CopyFile using Variable
Marcus - it worked! Thanks for the video. I realized what I was doing wrong and made the adjustment.
Regards,
Dom
Regards,
Dom