Author Topic: Debugger in 4.3 hangs MC on error  (Read 32806 times)

Ulfhednar

  • Contributor
  • VIP Member
  • *****
  • Posts: 513
    • View Profile
Debugger in 4.3 hangs MC on error
« on: May 31, 2014, 19:17:04 »
I know the debugger is very #beta# right now but thought I'd mention this -

MC 4.3 1691
Playing with the debugger I found it now crashes MC if it encounters a 'serious' syntax error.
Previously hitting 'stop' button & seeing the debugging stopped msg was enough to detach the debugger.
The stop button now stays 'lit' & the debugger must be shut down with X.  MC window hangs with 'not responding' white-out & needs to be closed via X & following crash dialog.

I decided to play with this question to reawaken my script knowledge - http://forum.multicommander.com/forum/index.php/topic,1184.0.html
Adding a folder with date works OK.
Adding time to date creates a crash or a folder called $date. (Obviously I have not given the variables correctly  ::))
 
Adding the time variable seems a potential problem as HH:MM:SS obviously can't be used for a name/path, (:'s), but with or without : I find in calling the FormatTime function I will see the hour but MM for minutes....?  My fault?  [See pic]

It would be interesting to know if a folder name using multiple variables is possible, & how far I am off!  ;)

Using the following
Code: [Select]
@var $now = GetTime();
@var $date = FormatDate( "dd-MM-yyyy", $now );
@var $nowLocal = FormatTime( "HHMM", $now);
@var $folder;
@var $FolderBaseName = GetSourcePath();
@var $arr = {"$date", "$nowLocal"};


{
 $folder = $FolderBaseName ^ $arr;
 MC.Filesystem.Makedir PATH="{$folder}"
 }

Gives \$date  :o
(Debug screen attached)

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4411
    • View Profile
    • Multi Commander
Re: Debugger in 4.3 hangs MC on error
« Reply #1 on: May 31, 2014, 23:40:30 »
Strange. It does not crash for me..


You know.. You do not need the extra { }

Code: [Select]
$folder = $FolderBaseName ^ $arr;Not sure what you think that would do.. $arr is an array, so you append that to a string only the first element is added.

But you do not need the array at all.. just write
$folder = $FolderBaseName ^ $date + " " + $nowLocal;

Also
Code: [Select]
@var $nowLocal = FormatTime( "HHMM", $now);the format is wrong..  minutes is lower case. "mm"

So you can write it like this.

Code: [Select]
@var $now = GetTime();
@var $date = FormatDate( "dd-MM-yyyy" , $now );
@var $time = FormatTime( "HHmm", $now);
@var $folder;
@var $FolderBaseName = GetSourcePath();

 $folder = $FolderBaseName ^ $date + " " +$time;
 MC.Filesystem.Makedir PATH="{$folder}"


Ulfhednar

  • Contributor
  • VIP Member
  • *****
  • Posts: 513
    • View Profile
Re: Debugger in 4.3 hangs MC on error
« Reply #2 on: June 01, 2014, 12:43:13 »
Thanks very much Mathias. 
I recall now you saying something about { } before, I can see the benefits of not needing them all the time. 

I hadn't been able to give the multiple $vars to the  $folder = $FolderBaseName ^ instruction without it crashing MC so
I had begun thinking perhaps multiple variables needed an array in this case - because they made a string....   ??? 

I also wondered how I might define a folder name based on things like filenames, root folder etc not just date & time.  I was wondering about something like this
Code: [Select]
@var $arr = PathGetParts( $src_path );but instead transposing filename to a new folder & adding date & time.  As the debugger kept hanging I didn't get very far.

The element I definitely didn't think to use was +   ::)  :o
Now you have given me more info I can return to this idea & see if I an make it work.  :)

I intend to keep playing about with MS when time allows as it is a great time saver for simple frequent tasks.
But I imagine by the time I figure it out you will have upgraded it all!  ;D

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4411
    • View Profile
    • Multi Commander
Re: Debugger in 4.3 hangs MC on error
« Reply #3 on: June 01, 2014, 13:08:51 »
I also wondered how I might define a folder name based on things like filenames, root folder etc not just date & time.  I was wondering about something like this
Code: [Select]
@var $arr = PathGetParts( $src_path );but instead transposing filename to a new folder & adding date & time.  As the debugger kept hanging I didn't get very far.
You can use PathGetParts to get an array with all the parts of the file paths split up.

But then you need to tell what part you want to use
like
Code: [Select]
@var $path = "C:\\MyFolder\\MyFiles.txt";
@var $arr = PathGetParts( $path );

@var $drive = $arr[0];
@var $path = $arr[1];
@var $filename = $arr[2];
$drive = "C:\"
$path = "C:\MyFolder\"
$filename = "MyFiles.txt"


If you only want the last Name part of a path you can use PathGetNamePart
Code: [Select]
@var $path = "C:\\MyFolder\\MyFiles.txt";
@var $filename = PathGetNamePart( $path );
$filename = "MyFiles.txt"

Or if you only want the path..  (Like remove the last path entry from the path)
Code: [Select]
@var $path = "C:\\MyFolder\\MyFiles.txt";
@var $pathPart = PathGetPathPart( $path );
$pathPart = "C:\MyFolder\"

Ulfhednar

  • Contributor
  • VIP Member
  • *****
  • Posts: 513
    • View Profile
Re: Debugger in 4.3 hangs MC on error
« Reply #4 on: June 01, 2014, 18:52:38 »
Thanks mathias thats great  :)

I now managed to modify my initial idea quite easily -
Code: [Select]
@var $now = GetTime();
@var $date = FormatDate( "dd-MM-yyyy" , $now );
@var $time = FormatTime( "HHmm", $now);
@var $folder;
@var $FolderBaseName = GetTargetPath();
@var $filename = GetSourceFocusName();


 $folder = $FolderBaseName ^ $filename + " " + $date + " " +$time +"Hrs";
 MC.Filesystem.Makedir PATH="{$folder}"

Giving me a folder in the target window with the source file selection & a time-stamp as its' name.
e.g.:- \mynewfolder.txt 01-06-2014 1700hrs

The folder name obviously includes the .ext so I am going to try the array approach to trim that from the name.
Wondering about opening the new folder in the target pane, I haven't found a 'Goto' type command yet. (To shift the focus to the newly created folder in the target pane).

Will post back my result.


Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4411
    • View Profile
    • Multi Commander
Re: Debugger in 4.3 hangs MC on error
« Reply #5 on: June 01, 2014, 19:16:26 »
MC.Explorer.Goto
For going to a path

Send 1 as second paramter to PathGetNamePart and it will strip file extension
http://multicommander.com/docs/multiscript/functions/filesystem#pathgetnamepart



Ulfhednar

  • Contributor
  • VIP Member
  • *****
  • Posts: 513
    • View Profile
Re: Debugger in 4.3 hangs MC on error
« Reply #6 on: June 01, 2014, 19:56:05 »
Thanks again, I had managed to forget the link between MC.Explorer commands & scripts in looking through all the script functions  :-[
You pre-empted my query on tokenize...!!  :D

----- I had been looking at this -
Code: [Select]
<array> StrTokenize2Array(<str> input, <str> delimiter);but it doesn't like this
Code: [Select]
$arr StrTokenize2Array($arr input, "." delimiter);
@var $name = $arr[0];
@var $ext = $arr[1];

Not sure what is wrong with my syntax  ::)   It splits the string into letters & gives $arr[xx] for each character but this is not useful for a filename that is not a constant pattern. 

But now I can skip past that issue for this script.  :P

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4411
    • View Profile
    • Multi Commander
Re: Debugger in 4.3 hangs MC on error
« Reply #7 on: June 01, 2014, 20:15:28 »
Thanks again, I had managed to forget the link between MC.Explorer commands & scripts in looking through all the script functions  :-[
You pre-empted my query on tokenize...!!  :D

----- I had been looking at this -
Code: [Select]
<array> StrTokenize2Array(<str> input, <str> delimiter);but it doesn't like this
Code: [Select]
$arr StrTokenize2Array($arr input, "." delimiter);
@var $name = $arr[0];
@var $ext = $arr[1];

Not sure what is wrong with my syntax  ::)   It splits the string into letters & gives $arr[xx] for each character but this is not useful for a filename that is not a constant pattern. 

But now I can skip past that issue for this script.  :P

Code: [Select]
@var $path = "C:\\MyFolder\\MyFiles.txt";
@var $arr = StrTokenize2Array($path, ".");
But the problem with that is that if any other part of the path happens to have a "." it will be bad.

You can also use string function
Code: [Select]
@var $path = "C:\\MyFolder\\MyFiles.txt";
@var $positionOfLastDot = StrRFind($path, ".");
@var $name = StrSub($path , 0, $positionOfLastDot);
@var $ext = StrSub($path , $positionOfLastDot, -1);

There are many ways to do the same thing :)

Ulfhednar

  • Contributor
  • VIP Member
  • *****
  • Posts: 513
    • View Profile
Re: Debugger in 4.3 hangs MC on error
« Reply #8 on: June 01, 2014, 20:19:58 »
This works well
Code: [Select]
@var $now = GetTime();
@var $date = FormatDate( "dd-MM-yyyy" , $now );
@var $time = FormatTime( "HHmm", $now);
@var $folder;
@var $FolderBaseName = GetTargetPath();
@var $path = GetSourceFocusName();
@var $name = PathGetNamePart( $path , 1 );


 $folder = $FolderBaseName ^ $name + " " + $date + " " +$time +"Hrs";
 MC.Filesystem.Makedir PATH="{$folder}"

MC.Explorer.Goto TARGET ="{$folder}"

My only problem is not getting the new folder to open in the inactive pane. 

Thanks for helping me get this far, I appreciate the fact that you have many more important things to do!  ;)

Ulfhednar

  • Contributor
  • VIP Member
  • *****
  • Posts: 513
    • View Profile
Re: Debugger in 4.3 hangs MC on error
« Reply #9 on: June 01, 2014, 20:25:14 »
We are Cross-posting I think!

I like the lastdot option for extensions, this will be useful if a version # is included in the source.

I guess the trick is finding the optimal solution given the possible uses.  It is great to have options tho, MS-DOS type environments are a nightmare   ;D

Thanks for giving me so many details on all this it will help me out a lot in the future.  :)  8)

Ulfhednar

  • Contributor
  • VIP Member
  • *****
  • Posts: 513
    • View Profile
Re: Debugger in 4.3 hangs MC on error
« Reply #10 on: June 01, 2014, 20:38:22 »
I found a way of doing it  :)

Code: [Select]
@var $now = GetTime();
@var $date = FormatDate( "dd-MM-yyyy" , $now );
@var $time = FormatTime( "HHmm", $now);
@var $folder;
@var $FolderBaseName = GetTargetPath();
@var $path = GetSourceFocusName();
@var $name = PathGetNamePart( $path , 1 );


 $folder = $FolderBaseName ^ $name + " " + $date + " " +$time +"Hrs";
 MC.Filesystem.Makedir PATH="{$folder}"

MC.SetActivePanel PANEL TOGGLE
MC.Explorer.Goto TARGET="{$folder}"


Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4411
    • View Profile
    • Multi Commander
Re: Debugger in 4.3 hangs MC on error
« Reply #11 on: June 01, 2014, 21:00:35 »
Code: [Select]
MC.SetActivePanel PANEL TOGGLE
Wrong you missing the =

MC.SetActivePanel PANEL=TOGGLE

But Goto with TARGET as you wrote above should also work
Just make sure there is no extra space between the OPTION name and the Parameter.

MC.Explorer.Goto TARGET="{$folder}"
« Last Edit: June 01, 2014, 21:03:25 by Mathias (Author) »

Ulfhednar

  • Contributor
  • VIP Member
  • *****
  • Posts: 513
    • View Profile
Re: Debugger in 4.3 hangs MC on error
« Reply #12 on: June 01, 2014, 22:58:32 »
I see.  That explains why I found some problems.  :)

My final script for today:-
  • Select a file;
  • Create folder in inactive pane, named for selected file & appending date & time;
  • Open the new folder in the inactive pane & move the file selected in the active pane, into the new folder in the inactive pane.

Code: [Select]
@var $now = GetTime();
@var $date = FormatDate( "dd-MM-yyyy" , $now );
@var $time = FormatTime( "HHmm", $now);
@var $folder;
@var $FolderBaseName = GetTargetPath();
@var $path = GetSourceFocusName();
@var $name = PathGetNamePart( $path , 1 );

$folder = $FolderBaseName ^ $name + " " + $date + " " +$time +"Hrs";
MC.Filesystem.Makedir PATH="{$folder}"
MC.Explorer.Goto TARGET="{$folder}" 

MC.SetActivePanel PANEL=TOGGLE
MC.Explorer.Select ONLYFILES="$path"
MC.Explorer.Move NODIALOG USEEXISTINGQUEUE

Baby steps I guess, but potentially useful   ;)
« Last Edit: June 01, 2014, 23:01:24 by Ulfhednar »

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4411
    • View Profile
    • Multi Commander
Re: Debugger in 4.3 hangs MC on error
« Reply #13 on: June 02, 2014, 08:07:32 »
If you just want to move the selected files into a date folder on the target path.

Then here is an alternative solution.
The target folder do not need to create first. By using MoveFile(...) you can set target path and if target folder does not exists it will be created.

Code: [Select]
@var $now = GetTime();
@var $date = FormatDate( "dd-MM-yyyy" , $now );
@var $time = FormatTime( "HHmm", $now);
@var $targetFolder;
@var $FolderBaseName = GetTargetPath();

// Get full path to file in focus
@var $path = GetSourceFocusPath();
@var $name = PathGetNamePart( $path , 1 );

// Build target path. and make sure that it ends with a slash so it knows that it is a folder.
$targetFolder = $FolderBaseName ^ $name + " " + $date + " " + $time +"Hrs" + "\\";

MoveFile( $targetFolder, $path , "NODIALOG, USEEXISTINGQUEUE, NOWAIT");
« Last Edit: June 02, 2014, 08:09:19 by Mathias (Author) »

Ulfhednar

  • Contributor
  • VIP Member
  • *****
  • Posts: 513
    • View Profile
Re: Debugger in 4.3 hangs MC on error
« Reply #14 on: June 02, 2014, 09:13:33 »
That is an interesting script, & will give me ideas!  :)
I can see I have a way to go to get near your understanding of this.

I have not noticed NOWAIT before.

I notice some cool new new folder F-key options in 4.3 b1694.  I will find these helpful.
Do these new functions have commands in the scripting (MS & MC.<command>) forms also?
Tho that may not be necessary given the script provided here.

Thank you for the assistance & the continued development of MC, don't know what I would do without it now.   ;)

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4411
    • View Profile
    • Multi Commander
Re: Debugger in 4.3 hangs MC on error
« Reply #15 on: June 02, 2014, 13:11:44 »
NOWAIT is only valid for the CopyFile/MoveFile command in the MultiScript function.. the MC.Explorer.Copy/Move do NOT support NOWAIT.

If you are doing anything on the file you are copying then to include NOWAIT.. With NOWAIT the script engine will not wait for the copy/move to complete before continuing.

No MC.Explorer.Makedir do not support the new extra F# commands. They are only usable for the dialog, and if you are scripting you can do that your self in script and even more anyway.



Ulfhednar

  • Contributor
  • VIP Member
  • *****
  • Posts: 513
    • View Profile
Re: Debugger in 4.3 hangs MC on error
« Reply #16 on: June 02, 2014, 19:00:37 »
I see.  8)
This makes MS quite dynamic, moreso than how I have imagined it to be. 

I will need to experiment more.  I'm only scratching the surface so far.   :)