Dropping files to Flash/External drive folders

Discuss and share scripts and script files...
klownboy
Posts: 4459
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.8037 at 100% 2560x1440

Dropping files to Flash/External drive folders

Post by klownboy »

Hi,
Don's new functionality for <getdrop> introduced in version 12.10.0002 gave me an idea on using it for copying files to external drives, like flash/external hard drives. I find myself doing that more and more lately to copy to other computers when my home network isn't the ideal way to go. There's an example of <getdrop> and the use of self("caption") in the help file under "self". I also was able to take advantage of Don's new undocumented caller("caption") similar to "self". It was discussed in this thread (PeterH's suggestion), http://www.xyplorer.com/xyfc/viewtopic. ... on+#p80846 It's actually kind of slick, since it saved me from having to use a variable after each label heading to establish the different folder locations. This will come in very handy in other scripts.

Anyway, I wanted to have a menu listing a number of different folder locations (or I suppose it could be different drives also) on the flash drive/external drive - choices to drop the files. It's a pain in the you-know-what sometimes to have to scroll down the tree to get to those external drives. I've been testing this by dropping files on the script itself (thanks Don) and it works fine, but I'll probably end up putting in a catalog item since we can't drop on a CTB (yet).

By the way Don, I noticed that "gettoken" would not work properly to trim more than one space (using "t" in formating option) when the separator was a special character (e.g., like a bullet symbol). I had to use only one space (It worked fine if I used a normal "-" with 2 spaces on each side as I did below. You need a nice built-in download icon (i.e., down arrow). :)

Code: Select all

"_Initialize"
    perm $Flash_Folder, $Rem_Dr; 

    $Rem_Dr = get("drives", 2), "|");
    $Dr_Cnt = gettoken($Rem_Dr, "count", "|");
    end $Dr_Cnt < "1", "You have no removable drives on-line, aborting!";
    if ($Dr_Cnt > "1") {
      status "You have more than one flash or external hard drive on-line!";
      $Rem_Dr = inputselect("Select the Target Drive: <crlf>","$Rem_Dr", | ,4, ,350, 250, "Target Drive Selection");}

"Select Flash Drive Folder|:wipe";   //Don to test add, load self(file);  or load *;  obviously get rid of the first ;
"-"
"        $Rem_Dr&";
    sub _drop_it;
"        $Rem_Dr&AHK";
    sub _drop_it;
"        $Rem_Dr&Downloads";
    sub _drop_it;
"        $Rem_Dr&Misc";
    sub _drop_it;
"        $Rem_Dr&XY";
    sub _drop_it;


"_drop_it";
     if (<get drop |> == ""){
       status "Nothing to do" , , "alert";
     }
     else {
       $Flash_Folder = ($Rem_Dr . gettoken(caller("caption"), -1, "&", "t"));
       if (exists($Flash_Folder) >= 1) {
              copyto $Flash_Folder, <get drop |>;
       }
       else {
             msg "This path doesn't exist!";
       }
     }  
"_Terminate"
 unset $Flash_Folder; unset $Rem_Dr;
Of course you will have to change the drive/folders locations. Once you do that, you should be able to drag and drop files on the script and the menu will display giving you a choice of folder locations. I realize I didn't need to use to use "_Initialize or "_Terminate" in this case, but I was just testing their functionality. :)
Ken
Edit: I made some tweaks to recognize the possibility of more than one flash or external hard drive, and if that's the case, allow you to select which one before selecting the folder to which we'll copy the file(s). Thanks highend for your example. It helped me greatly improve my initial version.
Last edited by klownboy on 15 Feb 2013 16:19, edited 6 times in total.

highend
Posts: 14946
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Dropping files to Flash/External drive folders

Post by highend »

Interesting idea, Ken!

A different approach (just threw it together, it isn't pretty (no icons)):
Why not create the list of drives with folders dynamically?

E.g.: Create a popup for all removable drives in one list (including their root dir).
My script filters out $Recycle.bin and System volume information because I used fixed drives at first.

My external sticks / hdds don't have that many folders on the root, so the list isn't overpopulated.
Fits (at least) more into my workflow and you don't have to redefine folders / edit the script because of it).

Code: Select all

	$menu = "";
	foreach($drive, get("drives", 2), "|") { $menu = $menu . "$drive|" . regexreplace(folderreport("dirs", "r", $drive, , , "|"), "[A-Z]:\\(\$RECYCLE\.BIN[|]|System Volume Information[|])", "") . "|-|"; }
	$caller = popupmenu($menu);
	if($caller != "") { copyto $caller, <get drop |>; }
Hey, it's a four-liner *g*

P.S.: Thanks for your e-mail, I'll write back during the week :)
One of my scripts helped you out? Please donate via Paypal

admin
Site Admin
Posts: 66304
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Dropping files to Flash/External drive folders

Post by admin »

Happy to see that the new stuff is of some use. But I have to go back to Carnival now... :biggrin:

highend
Posts: 14946
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Dropping files to Flash/External drive folders

Post by highend »

A small addition for those who want a combination of fixed & variable folders:

Code: Select all

	$fixedFolders = "G:\Videos|G:\Photos|-|"; // |-| must be appended!
	$menu = "";
	foreach($drive, get("drives", 2), "|") { $menu = $menu . "$drive|" . regexreplace(folderreport("dirs", "r", $drive, , , "|"), "[A-Z]:\\(\$RECYCLE\.BIN[|]|System Volume Information[|])", "") . "|-|"; }
	$menu = $fixedFolders . $menu;
	$caller = popupmenu($menu);
	if($caller != "") { copyto $caller, <get drop |>; }
One of my scripts helped you out? Please donate via Paypal

klownboy
Posts: 4459
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.8037 at 100% 2560x1440

Re: Dropping files to Flash/External drive folders

Post by klownboy »

Hey highend, While you posted your last post as I was posting some tweaks to my initial version. :) I don't typically have more than one flash/external drive installed (95% of the time it's just one), but your first post in this thread got me thinking about multiple drives and bit more flexibility as you have done in your 2nd post. Of most importance, was your use of get("drives", 2) to obtain the drive letter(s) since as you know that can change depending on many factors. When I initially ran your first post script my folder listing went off the page (i.e., I needed to scroll the list). Yes, :biggrin: I had way too many folders. I had just finished building a new computer so I was doing loads of transfers to various locations on the new computer. Under normal situations though I tend to have the same basic folder layouts on all my flash drives (e.g., I:\, I:\downloads, I:\misc, I:\AHK, I:\XY) and obviously, it's to those folders that 95% of the time I make transfers.

I do like the new flexibility you built into your 2nd version for fixed locations. I'm still trying to digest and understand the long foreach line...WoW!

If/when you get a chance, could you take a look a my last modified version (on 1st post). When more than one removable drive is detected, I was hoping to use "inputselect" to provide the user the choice of which drive to make the copy to instead of using "popupmenu", but I'm struggling on how to properly separate the returned drives and then use them with the inputselect command. Actually while writing, I may have just figured it out...I may be able to use the variable $Rem_Dr (in my post) directly in as the "listdata" area of select input since it's already separated by "|". I'll play some more!

Edit: Highend, I did figure out how to use inputselect in lieu of popupmenu. I'll modify my 1st post with a comment on how to use it instead, but I may just stick with popupmenu myself...for this situation it's simpler looking.

Thanks again for your help,
Ken

highend
Posts: 14946
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Dropping files to Flash/External drive folders

Post by highend »

Hi Ken,

most of the time, my external usb 3 backup drive and one additional usb stick are plugged in. That's the reason I thought of something "more dynamic" :)

If you don't assign fixed drive letters to such drives (e.g. with USBDLM or by windows inbuild drive management tools) it isn't assured that they always get the same letter. That was my second reason.

I'm not a big fan of the inputfolder command but inputselect can be very convenient if you create a good (folder) structure. Scrollable and beeing able to use the keyboard (including typing letters to narrow the list down). I use it in many scripts (were appropriate ofc).

I currently thinking about a way to display the folder structure in a hierarchical way through the use of inputselect but I'm unsure if this would be of any use for the broad mass of users. Maybe it's more tailored to myself ;)

I have to admit, the condensed foreach loop is hard to interpret.
I'm just doing a folderreport on each drive to get the subfolders (not recursively) and filter out "$Recycle" and "System Information" folders. The rest is just concatenating of items :)

This is probably bad coding style, but it saves so much space *g*

Back to work!

Regards,
Highend
One of my scripts helped you out? Please donate via Paypal

klownboy
Posts: 4459
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.8037 at 100% 2560x1440

Re: Dropping files to Flash/External drive folders

Post by klownboy »

Hey highend,
I suppose everyones needs when it comes to the use of removable drives will be different. So the different approaches is a good thing. With my last change, I like being able to select the drive if and only if, I do happen to have more than one connected and then from there choose the folder.

As you say, I should take the time to assign my various external hard drives and flash drives fixed drive letters.

You said, "The rest is just concatenating of items", well, that's the part I have the most difficulty figuring out.

I do try to keep the file structure very similar on the hard drives of 3 different computers and also the flash/ext drives. For sync of my photos and other important files and programs across the computers and the external hard drives, I use a separate program, Allway Sync (which does bind the drive characteristics incase the letters change).

Take care,
Ken

admin
Site Admin
Posts: 66304
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Dropping files to Flash/External drive folders

Post by admin »

klownboy wrote:By the way Don, I noticed that "gettoken" would not work properly to trim more than one space (using "t" in formating option) when the separator was a special character (e.g., like a bullet symbol). I had to use only one space (It worked fine if I used a normal "-" with 2 spaces on each side as I did below.
Cannot find a problem here. Can you give an example?

klownboy
Posts: 4459
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.8037 at 100% 2560x1440

Re: Dropping files to Flash/External drive folders

Post by klownboy »

Don, I've been trying to reproduce and can't. It happened too many revisions ago. I was using a bullet symbol that you get by holding down the alt key and pressing 007 (on the keypad). I think at the time I may have been using a positive index "1" with gettoken and I probably should have been using 2 or -1, but for some reason it was working with one space on each side of the bullet but not when I had two spaces. Don't waste your time on it. If I stumble on it again and I tend to doubt it now, I'll let you.
Thanks,
Ken

klownboy
Posts: 4459
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.8037 at 100% 2560x1440

Re: Dropping files to Flash/External drive folders

Post by klownboy »

Is there any way of avoiding the display of a menu when you want to end/quit/abort the script. Take my example in the first post (I updated it again today). The whole purpose of the script is to drop files onto a script via the catalog, or as of today a CTB (thanks Don), a menu displays and we select the folder to which we'd like to copy the dragged files. If there's more than one drive it gives you a choice of which one to use.

Up front in the script (in "_Initialize"), I'm checking for the existence of a removable drive. If no drive is present/on-line, an error message will tell you that, however, the menu for drive selction still shows up. Is there any way to keep that from happening? I tried numerous things, "end", "if" statements, "sub", "load". Nothing bypassing the menu from showing. I know I could use "popupmenu" or "inputselect" instead of a menu, but in many cases I'd rather stick with a menu.

Don, if there isn't currently anything that would bypass the menu from showing, could you come up with something that could truely kill the script and prevent the menu from displaying (i.e., if we are in the "_Initialize script and we want to abort or escape the script we should be able to do that (hopefully) without a menu displaying).
Thanks,
Ken

admin
Site Admin
Posts: 66304
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Dropping files to Flash/External drive folders

Post by admin »

I'll think about it...

admin
Site Admin
Posts: 66304
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Dropping files to Flash/External drive folders

Post by admin »

Will be handled in the next version.

klownboy
Posts: 4459
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.8037 at 100% 2560x1440

Re: Dropping files to Flash/External drive folders

Post by klownboy »

Thanks Don once again. I think that capability will come in very useful especially in conjunction with your other new feature "_Initialize" _Terminate".
Ken

klownboy
Posts: 4459
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.8037 at 100% 2560x1440

Re: Dropping files to Flash/External drive folders

Post by klownboy »

Don,
In the first post in this thread the menu no longer displays if you cancel out or in this specific case, no removable drive is installed. The message, "You have no removable drives on-line, aborting!" displays and the script ends with no display of the menu. Thanks, it will be a handy feature in scripting along with "_Initialize".

I did notice something that may or may not be an issue. In the first "menu" line above, "Select Flash Drive Folder|:wipe"; I added load self(file) so it read "Select Flash Drive Folder|:wipe" load self(file); with the intent that if someone hit the heading instead of a menu item by mistake, it would simply reload the menu (I've seen the technique done in the forum), but instead I received an error message, "Command 'load' called with empty 'resource' argument". I tried the same command in another script menu and it worked fine as before, but that script does not have "_Initialize".

When I used, load * instead, the script runs again as you would expect, but it performs "_Terminate" twice, one right after the other. When stepping through the script, the Script Step by Step box reads on the first run of "_Terminate":

Code: Select all

 file: Internal   Script: Terminate Stack Size 1
Note: It ran "_Initialize" again also which I didn't want (but is logical), but I suppose I could bypass that by directing the load to a specific script within the MSR file?
On the second run, The Script Step by Step box reads "_Terminate":

Code: Select all

file: Internal   Script: Terminate
Obviously, you would not see this if you weren't in Step Mode. I figured I'd pass it on to see if you thought it could be a potential issue. Since the script was essentially reloaded I suppose it makes sense that it would run "_Terminate" twice (2 stacks), but maybe this is a by-product of the new ":_Initialize and "_Terminate" and using load self(file) or load *.
Thanks,
Ken

admin
Site Admin
Posts: 66304
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Dropping files to Flash/External drive folders

Post by admin »

Could you post the complete script that generates this issue, please?

Post Reply