Author Topic: CopyFile has me Beaten  (Read 17189 times)

AlanJB

  • VIP Member
  • *****
  • Posts: 433
  • VERY old Programmer
    • View Profile
CopyFile has me Beaten
« 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);

Jungle

  • Contributor
  • VIP Member
  • *****
  • Posts: 536
  • Old Skull
    • View Profile
Re: CopyFile has me Beaten
« Reply #1 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
« Last Edit: April 21, 2016, 19:40:51 by Jungle »

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4407
    • View Profile
    • Multi Commander
Re: CopyFile has me Beaten
« Reply #2 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);

AlanJB

  • VIP Member
  • *****
  • Posts: 433
  • VERY old Programmer
    • View Profile
Re: CopyFile has me Beaten
« Reply #3 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...  :-\