I've never done anything with XYplorer's built-in scripting language.
So maybe someone could help me automate this:
Operate on the selection in the list pane. If the name ends in "-SAVE" then copy it to the un-saved name. For example, "foo-SAVE" will be copied to "foo", so now I have "foo" and "foo-SAVE" with identical contents. foo is a directory in my case now, but it would be great if it worked for files and directories equally well.
If the name does not end in "-SAVE", then rename it so that it does. "foo" becomes "foo-SAVE".
It should work with multiple selections. E.g. I ctrl-click two directories in the list pane.
Also, given such a script, what's the easiest way to invoke it? I'm not committed to that naming convention--that's just what I'm using at the moment. So if it were "foo.SAVE" instead, a file-extension association with *.SAVE could do the restore operation. But it would need to use a different method to SAVE it, and that might be confusing. Just thinking...
"save" directory or file ?
-
JDługosz
- Posts: 121
- Joined: 17 Dec 2007 23:22
- Contact:
-
highend
- Posts: 14940
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: "save" directory or file ?
Code: Select all
foreach($item, "<get SelectedItemsPathNames |>") {
if (exists($item) == 2) { $baseName = getpathcomponent($item, "file"); $ext = ""; } // Folder
else { $baseName = getpathcomponent($item, "base"); $ext = "." . getpathcomponent($item, "ext"); } // File
if (regexmatches($baseName, "-SAVE$") != "") { // Contains "-SAVE"
$newName = regexreplace($baseName, "-SAVE$");
copyitem $item, "<curpath>\" . $newName . $ext;
} else { // Does not contain "-SAVE"
renameitem($baseName . "-SAVE" . $ext, $item);
}
}One of my scripts helped you out? Please donate via Paypal
-
JDługosz
- Posts: 121
- Joined: 17 Dec 2007 23:22
- Contact:
Re: "save" directory or file ?
Thanks. I pasted it in the edit box when creating an entry for the User menu. When I select the new command, it pops up another menu showing "foreach($item, "<get SelectedItemsPathNa…" on one line and just "}" on another. It seems to be a menu because of how the highlight follows the cursor between the two lines.highend wrote: Test it...
I'm confused.
-
highend
- Posts: 14940
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: "save" directory or file ?
Show a screenshot of where you tried to paste it. You either removed the indentation or put it into a single line edit box.
One of my scripts helped you out? Please donate via Paypal
-
JDługosz
- Posts: 121
- Joined: 17 Dec 2007 23:22
- Contact:
Re: "save" directory or file ?
highend wrote:Show a screenshot of where you tried to paste it. You either removed the indentation or put it into a single line edit box.
To see the attached files, you need to log into the forum.
-
highend
- Posts: 14940
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: "save" directory or file ?
As you can see the "foreach" and the closing "}" are on the same column 1.
Just put at least one space / tab before both of them.
Just put at least one space / tab before both of them.
One of my scripts helped you out? Please donate via Paypal
-
JDługosz
- Posts: 121
- Joined: 17 Dec 2007 23:22
- Contact:
Re: "save" directory or file ?
Thanks... that's less than intuitive, I must say.
-
bdeshi
- Posts: 4256
- Joined: 12 Mar 2014 17:27
- Location: Asteroid B-612
- Contact:
Re: "save" directory or file ?
That's a syntax rule for XYscripts.
To read more, enter this in the addressbar of XY:
To read more, enter this in the addressbar of XY:
Code: Select all
::help "idh_scripting.htm#idh_scripting_multi";Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]
[ this user is asleep ]
-
JDługosz
- Posts: 121
- Joined: 17 Dec 2007 23:22
- Contact:
Re: "save" directory or file ?
I had looked through the script docs a little, to see where I would put a script. Ended up seeing that User Command had a blank for that, so it stashed it away someplace.
I thought the indent thing was specifically for script files.
I thought the indent thing was specifically for script files.
XYplorer Beta Club