Multi Commander Support Forum

Multi Commander => Script => Topic started by: AlanJB on April 21, 2016, 18:34:08

Title: CopyFile has me Beaten
Post by: AlanJB on April 21, 2016, 18:34:08
I am trying to write a hotkeyed command to copy the file in focus to the current path.  Can some kind soul please explain why this fails (the Debugger seems to have no issue with it)?

Code: [Select]
@var $file = GetSourceFocusPath();
@var $path = PathGetPathPart($file);
@var $name = PathGetNamePart($file, 1);
@var $ext = PathGetFileExtPart($file);
@var $copytext = $path + $name + " - Copy" + $ext;
CopyFile($path, $copytext);
Title: Re: CopyFile has me Beaten
Post by: Jungle on April 21, 2016, 19:37:57
It fails because you're trying to copy non-existing file ($copytext).
CopyFile seems to copy existing file/folder to existing path
Title: Re: CopyFile has me Beaten
Post by: Mathias (Author) on April 21, 2016, 21:48:47
As Jungle said.. you send CopyFile the wrong paramters..  First is TargetName,  second is SourceFile.
http://multicommander.com/docs/multiscript/functions/filesystem#copyfile

Code: [Select]
@var $SourceFile = GetSourceFocusPath();
@var $path = PathGetPathPart($SourceFile);
@var $name = PathGetNamePart($SourceFile, 1);
@var $ext = PathGetFileExtPart($SourceFile);
@var $TargetFile = $path + $name + " - Copy" + $ext;
CopyFile($TargetFile, $SourceFile);
Title: Re: CopyFile has me Beaten
Post by: AlanJB on April 22, 2016, 09:44:43
Thanks Jungle and Mathias: that did it.

You'd think that after 45+ years of programming I would have learnt to read the documentation more carefully...  :-\