Multi Commander > Script
Some misbehaving
Kreator:
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: ---@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"
--- End code ---
Where is a mistake?
2. On some part I want to concatenate some strings. I write obvious thing:
--- Code: ---@var $targetpath = $rightdir + "\" + $leftdrive + "\" +$leftrelpath;
//all vars are strings
--- End code ---
, but I get no result. If I use
--- Code: ---@var $targetpath = $rightdir + "\" + $leftdrive;
$targetpath = $targetpath + "\" +$leftrelpath;
--- End code ---
, 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: ---@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, "");
--- End code ---
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 ;)
Mathias (Author):
--- Quote from: Kreator 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: ---@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"
--- End code ---
--- End quote ---
The array contains Drive , Path, filename (if exists).. if the doc say anything else it is wrong.
--- Quote from: Kreator on June 27, 2014, 21:34:33 ---2. On some part I want to concatenate some strings. I write obvious thing:
--- Code: ---@var $targetpath = $rightdir + "\" + $leftdrive + "\" +$leftrelpath;
//all vars are strings
--- End code ---
--- End quote ---
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: ---@var $targetpath = $rightdir + "\\" + $leftdrive + "\\" +$leftrelpath;
--- End code ---
But you do not need to add \ at all.. you ^ instead ( special path append operator ) it will add \ if it is needed.
--- Code: ---@var $targetpath = $rightdir ^ $leftdrive ^ $leftrelpath;
--- End code ---
--- Quote from: Kreator on June 27, 2014, 21:34:33 ---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: ---@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, "");
--- End code ---
--- End quote ---
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", "" );
Kreator:
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!
Ulfhednar:
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):
--- Quote from: Ulfhednar 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.
--- End quote ---
No CopyFile(..) do not support array.. copyfile copy 1 folder or 1 file..
--- Quote from: Kreator on June 27, 2014, 23:14:02 ---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.
--- End quote ---
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)
Navigation
[0] Message Index
[#] Next page
Go to full version