Author Topic: Some misbehaving  (Read 24984 times)

Kreator

  • Junior Member
  • **
  • Posts: 32
    • View Profile
Some misbehaving
« on: June 27, 2014, 21:34:33 »
Hello.
Tonight I wanted to make something like god old xcopy script for fast backing up my C drive files and folders to make it easy to restore later.
I've started with string handling functions and got some problems:
1. In example to PathGetParts function see, that should get a drive, a path and a file/folder name in the array. But I get the path with drive in the Path cell somehow. Here's what I do:
Code: [Select]
@var $leftselection = GetSourceFocusPath();
@var $pathparts = PathGetParts($leftselection);
//$pathparts[1] shows me "C:\Users\...\and so on", in user manual it looks like "Users\...\and so on"
Where is a mistake?
2. On some part I want to concatenate some strings. I write obvious thing:
Code: [Select]
@var $targetpath = $rightdir + "\" + $leftdrive + "\" +$leftrelpath;
//all vars are strings
, but I get no result. If I use
Code: [Select]
@var $targetpath = $rightdir + "\" + $leftdrive;
$targetpath = $targetpath + "\" +$leftrelpath;
, it works fine. Should it work like this?
3. Finally, I've managed to kill MC with my crazy code (it is not correct to make what I want, but its syntax is ok and should work fine):
Code: [Select]
@var $leftdir = GetSourcePath();
MessageBox("leftdir", $leftdir, 0);
@var $leftselection = GetSourceFocusPath();
MessageBox("leftselection", $leftselection, 0);
@var $pathparts = PathGetParts($leftselection);
@var $rightdir = StrTrimRight(GetTargetPath(), "\");
MessageBox("rightdir", $rightdir, 0);
@var $leftdrive = StrTrimRight($pathparts[0], ":\");
MessageBox("leftdrive", $leftdrive, 0);
MessageBox("pathparts[0]", $pathparts[0], 0);
MessageBox("pathparts[1]", $pathparts[1], 0);
MessageBox("pathparts[2]", $pathparts[2], 0);
@var $leftrelpath = StrTrimRight($pathparts[1], "\");
MessageBox("leftrelpath", $leftrelpath, 0);
@var $targetpath = $rightdir + "\" + $leftdrive;
$targetpath = $targetpath + "\" +$leftrelpath;
MessageBox("targetpath", $targetpath, 0);
CopyFile($targetpath + "\*", $leftselection, "");
The CopyFile command causes crash after I press Cancel. The target path is wrong, but anyway, I cancel the operation so MC shouldn't crash.
That's all for now, see you later ;)
Save our fragile planet!

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4416
    • View Profile
    • Multi Commander
Re: Some misbehaving
« Reply #1 on: June 27, 2014, 22:33:46 »
Hello.
Tonight I wanted to make something like god old xcopy script for fast backing up my C drive files and folders to make it easy to restore later.
I've started with string handling functions and got some problems:
1. In example to PathGetParts function see, that should get a drive, a path and a file/folder name in the array. But I get the path with drive in the Path cell somehow. Here's what I do:
Code: [Select]
@var $leftselection = GetSourceFocusPath();
@var $pathparts = PathGetParts($leftselection);
//$pathparts[1] shows me "C:\Users\...\and so on", in user manual it looks like "Users\...\and so on"
The array contains Drive , Path, filename (if exists)..  if the doc say anything else it is wrong.

2. On some part I want to concatenate some strings. I write obvious thing:
Code: [Select]
@var $targetpath = $rightdir + "\" + $leftdrive + "\" +$leftrelpath;
//all vars are strings
You can not use "\"   \ is a escape char and are used to create special character. \r (return) \n (newline) \t (tab), If you need \ then you need to use double \\
Code: [Select]
@var $targetpath = $rightdir + "\\" + $leftdrive + "\\" +$leftrelpath;But you do not need to add \ at all.. you ^ instead ( special path append operator ) it will add \ if it is needed.
Code: [Select]
@var $targetpath = $rightdir  ^ $leftdrive  ^ $leftrelpath;
3. Finally, I've managed to kill MC with my crazy code (it is not correct to make what I want, but its syntax is ok and should work fine):
Code: [Select]
@var $leftdir = GetSourcePath();
MessageBox("leftdir", $leftdir, 0);
@var $leftselection = GetSourceFocusPath();
MessageBox("leftselection", $leftselection, 0);
@var $pathparts = PathGetParts($leftselection);
@var $rightdir = StrTrimRight(GetTargetPath(), "\");
MessageBox("rightdir", $rightdir, 0);
@var $leftdrive = StrTrimRight($pathparts[0], ":\");
MessageBox("leftdrive", $leftdrive, 0);
MessageBox("pathparts[0]", $pathparts[0], 0);
MessageBox("pathparts[1]", $pathparts[1], 0);
MessageBox("pathparts[2]", $pathparts[2], 0);
@var $leftrelpath = StrTrimRight($pathparts[1], "\");
MessageBox("leftrelpath", $leftrelpath, 0);
@var $targetpath = $rightdir + "\" + $leftdrive;
$targetpath = $targetpath + "\" +$leftrelpath;
MessageBox("targetpath", $targetpath, 0);
CopyFile($targetpath + "\*", $leftselection, "");
No Idea. too much to look at now.. 

But not sure you can not have filter like * in the target path. Target need to be a folder where the file should be copied to.
Like CopyFile( "C:\\Temp\\" , "D:\\MyFolder\\myFile.dat", "" );

« Last Edit: June 27, 2014, 22:35:31 by Mathias (Author) »

Kreator

  • Junior Member
  • **
  • Posts: 32
    • View Profile
Re: Some misbehaving
« Reply #2 on: June 27, 2014, 23:14:02 »
Thank you for fast reply ;)
1. I see.
2. Oh, poor me. Thanks for that nice operator!
3. Right you are, \* is not needed.
Another question: How to refresh a tab after the copy process finished? I've tried MC.Explorer.Refresh with all options, but it does nothing. Only F5 button helps...
And one more, please: How can I do such copy for several selected objects? Should I use user defined function and call it in for loop? I just don't get how can I give a file list to a copy command.
Thank you!
Save our fragile planet!

Ulfhednar

  • Contributor
  • VIP Member
  • *****
  • Posts: 514
    • View Profile
Re: Some misbehaving
« Reply #3 on: June 28, 2014, 09:51:15 »
If I understand correctly, passing the selection can be achieved with something from here -
http://multicommander.com/docs/multiscript/functions/getfilefromview
Then you can pass an array of selections to your chosen commands. 

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4416
    • View Profile
    • Multi Commander
Re: Some misbehaving
« Reply #4 on: June 28, 2014, 10:36:52 »
If I understand correctly, passing the selection can be achieved with something from here -
http://multicommander.com/docs/multiscript/functions/getfilefromview
Then you can pass an array of selections to your chosen commands.
No CopyFile(..) do not support array..   copyfile copy 1 folder or 1 file..

Another question: How to refresh a tab after the copy process finished? I've tried MC.Explorer.Refresh with all options, but it does nothing. Only F5 button helps...
And one more, please: How can I do such copy for several selected objects? Should I use user defined function and call it in for loop? I just don't get how can I give a file list to a copy command.
views are refreshed by them self by it can not refresh while the script is running so it happens after so if you run step by step in the debugger it might look like it does not update.
There is no CopyFiles(...) yet.. It is planed to add but not had the time.
You can do it in a loop.  and if you use NOWAIT and USEEXISTINGQUEUE then all of them will be queued to the same queue.
And if you skip NOWAIT for the LAST item then it will wait and block on the last item if you really need it to block. (Since all Copy operations are done in background threads)



Kreator

  • Junior Member
  • **
  • Posts: 32
    • View Profile
Re: Some misbehaving
« Reply #5 on: June 28, 2014, 12:13:23 »
OK, I got it about CopyFiles, will try to implement, thank you.
And the view doesn't refresh even after the script finishes. I don't use any debugger. For now the code is
Code: [Select]
@var $leftselection = GetSourceFocusPath();
@var $pathparts = PathGetParts($leftselection);
@var $rightdir = StrTrimRight(GetTargetPath(), "\");
@var $leftdrive = StrTrimRight($pathparts[0], ":\");
@var $leftrelpath = StrTrimLeft(StrTrimRight($pathparts[1], "\"), $pathparts[0]);
@var $targetpath = $rightdir ^ $leftdrive ^ $leftrelpath;
CopyFile($targetpath, $leftselection, "");
It works fine, but I see no result in the opposite pane, I have to press F5 after it finishes. Maybe there's some alternate method of copying, that will refresh the view while it works, like GUI Copy command?
Save our fragile planet!

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4416
    • View Profile
    • Multi Commander
Re: Some misbehaving
« Reply #6 on: June 28, 2014, 15:39:28 »
I think it is because the script engine is blocking the UI, So the refresh request is lost

Kreator

  • Junior Member
  • **
  • Posts: 32
    • View Profile
Re: Some misbehaving
« Reply #7 on: July 16, 2014, 21:13:54 »
Refreshing after copy works fine now since 4.4.1724.
Thank you!
Save our fragile planet!