copyfile is not renaming file it creates new sub-folder.

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
bbrink
Pro Scripter
Posts: 70
Joined: Thu Dec 31, 2009 2:36 am
Location: Minnesota
Contact:

copyfile is not renaming file it creates new sub-folder.

Post by bbrink » Wed Nov 24, 2010 5:06 am

HI,

I am trying to copy a file into another folder and rename it at the same time. Instead, this creates a sub-folder in the target folder.

Any idea why and how to get around it?

Let>CF_OVERWRITE=1
CopyFile>K:\Installers\_CurrentParts\Install_*.exe,K:\Installers\Project\.exe

Win 7 x 64 running Macro Sched. 11.1.19

thanks,

Bob

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

Post by Marcus Tettmar » Wed Nov 24, 2010 7:03 am

Trying to copy potentially multiple files (*.exe) to one file (.exe) is nonsensical and confusing so Windows thinks you want to move those files (*.exe) to a new subfolder (.exe).

You can't do a copy where the source is potentially many files and the destination is one file.

If the issue is that you don't know what the full name of the source is, and if it is safe to assume there is only one matching file in the source folder you could do:

Code: Select all

CopyFile>K:\Installers\_CurrentParts\Install_*.exe,K:\Installers\Project\
GetFileList>K:\Installers\Project\Install_*.exe,file_list
Separate>file_list,;,files
If>files_count>0
  Renamefile>files_1,K:\Installers\Project\.exe
Endif
If there are more than one matching source file this would rename only the first. I'm not sure what you would want to do if there are more than matching source file because they can't all end up with the same name in the same folder!
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

bbrink
Pro Scripter
Posts: 70
Joined: Thu Dec 31, 2009 2:36 am
Location: Minnesota
Contact:

Post by bbrink » Wed Nov 24, 2010 12:39 pm

Hi,

I mis-spoke. My intent is a 1 to 1 relationship between source and target files.

My use of the wildcard is accidently qualifying more than one file.

I tried using question marks first (ala DOS) but that had same result. Are there any "placeholder" type wildcards that would only affect one character each?

Bob

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

Post by Marcus Tettmar » Wed Nov 24, 2010 12:45 pm

My answer remains the same. Regardless of the number of wildcard characters a wildcard of any kind has the potential for many files to match. So the solution remains the code in my previous reply.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

bbrink
Pro Scripter
Posts: 70
Joined: Thu Dec 31, 2009 2:36 am
Location: Minnesota
Contact:

Post by bbrink » Wed Nov 24, 2010 1:10 pm

Marcus,

I believe the issue is my use of wildcards. Do you have a wildcard that works on a single characer, similar to DOS?

Is it still true that he behavior for files is supports multiple wildcards in combination with other text? (if found that elsewhere in the forum)

mydir/r*d*.txt

means there has to be an r and a d and there might be other characters where the *'s are?

It sems as though this

Code: Select all

CopyFile>K:\Installers\_CurrentParts\Install*DPRW.exe, k:\installers\projects\InstallDP.exe
Is ignoring the DPRW part of the source mask and therefor finding more than one source and creating a folder instead of a file.

thanks again, I greatly appreciate your help.

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

Post by Marcus Tettmar » Wed Nov 24, 2010 1:46 pm

Install*DPRW.exe will and does find all files which start "Install" and end "DPRW.exe". Which could be one or more files. Wildcards imply the potential for multiple matches regardless of how you use them.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

bbrink
Pro Scripter
Posts: 70
Joined: Thu Dec 31, 2009 2:36 am
Location: Minnesota
Contact:

Post by bbrink » Wed Nov 24, 2010 2:21 pm

Hi,

Since I have asked it twice and you have not answered am I to assume that you do not have a wildcard that works on a single characer, similar to DOS?

There is only one file that starts with "Install" and ends with "DPRW", yet I still get a folder created instead of a file copied.

Bob

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

Post by Marcus Tettmar » Wed Nov 24, 2010 2:24 pm

Sorry, we both seem to be repeating ourselves. I thought I had answered that. No, there is only the * character which will match any chars.
There is only one file that starts with "Install" and ends with "DPRW", yet I still get a folder created instead of a file copied.
I have tried to explain several times, that while you may only have one file that matches, the file spec given has the potential to match multiple files. Therefore Windows has to assume that the destination is a folder because you can't copy multiple files to one file (unless you are doing some kind of append which doesn't apply in this case).
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

bbrink
Pro Scripter
Posts: 70
Joined: Thu Dec 31, 2009 2:36 am
Location: Minnesota
Contact:

Post by bbrink » Wed Nov 24, 2010 2:35 pm

Marcus,

Thanks again for the clarification. I understand now. In retrospect I probably should have provided more information earlier, instead I was trying to keep it simple and failed at that! Kudos to you, thanks again!

Bob

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