With version 9.90.1000 when swapping the names of 2 files, you are allowed to select files with different extensions. The swap includes the extension. Can this be changed to leave the extension alone, as most of the options on the Rename Special menu do?
I've gottem myself into much trouble by swapping the names of, say a JPG file and a PSD file. When XYPlorer was in thumbnail view, and I was looking at a folder with almost 300 pictures (JPG and PSD, a few TIF's) and it hit a misnamed file -- a JPG file that had a PSD extension. This hung XYPlorer at the point of generating its thumbnail, and I had to shut the program down from Task Manager. I'd be embarassed to tell you how long it took me to figure out the problem and fix it.
Swap file names -- don't swap extensions?
-
highend
- Posts: 14954
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: Swap file names -- don't swap extensions?
Don't know if Don will change that.
I just wrote a quick and dirty script that you can use for a toolbar button or anything else that can invoke a script:
It checks if you really! selected a pair of folders or files (not a mix of them ofc) and will retain the original extension for files. The first selected item gets a temporary name to avoid name conflicts (if files have the same extension or for folders in general).
I just wrote a quick and dirty script that you can use for a toolbar button or anything else that can invoke a script:
It checks if you really! selected a pair of folders or files (not a mix of them ofc) and will retain the original extension for files. The first selected item gets a temporary name to avoid name conflicts (if files have the same extension or for folders in general).
Code: Select all
/* 06.08.2011, swap the names of two files. Leave the extension alone
::load "<xyscripts>\SwapFileNames.xys";
Remarks: Two files or two folders on one pane must be selected
*/
setting('BackgroundFileOps', 0);
// Get current path
$CurrentPath = "<curpath>";
// Get selected items
$SelectedFilesOrFolders = get("SelectedItemsPathNames", "|");
// If nothing || one file / folder || more than two files / folders are selected, abort script
end (getinfo("CountSelected") <= 1 || getinfo("CountSelected") >= 3), "You haven't selected a pair of files or folders, aborted!";
// Check if a single | multiple files, a folder or a drive is selected
// False = folder | True = file | Drive = drive
$CheckFileOrFolder = report("{Dir False|True|Drive}|", 1);
$CheckItem1 = gettoken("$CheckFileOrFolder", 1, "|");
$CheckItem2 = gettoken("$CheckFileOrFolder", 2, "|");
end($CheckItem1 != $CheckItem2), "Your selected items are not a file or folder pair!, aborted";
if("$CheckItem1" == "True" && "$CheckItem2" == "True") {
// A pair of files is selected
// Get the base name of the two files
$FirstSelectedItem = gettoken("$SelectedFilesOrFolders", 1, "|");
$FileBaseName1 = regexreplace($FirstSelectedItem, "(.*\\)(.*(?=\.))(.*)", "$2");
$Extension1 = regexreplace($FirstSelectedItem, "(.*\.)(.*)", "$2");
$SecondSelectedItem = gettoken("$SelectedFilesOrFolders", 2, "|");
$FileBaseName2 = regexreplace($SecondSelectedItem, "(.*\\)(.*(?=\.))(.*)", "$2");
// First file has to get a temp name before the real rename occurs if the file extension is the same!
$TempFileBaseName1 = ~TempFileName1;
$NewFirstSelectedItem = $CurrentPath . "\" . $TempFileBaseName1 . "." . $Extension1;
// Rename them
rename s, "$FileBaseName1/$TempFileBaseName1", , "$FirstSelectedItem";
rename s, "$FileBaseName2/$FileBaseName1", , "$SecondSelectedItem";
rename s, "$TempFileBaseName1/$FileBaseName2", , "$NewFirstSelectedItem";
} else {
// A pair of folders is selected
// Get the base name of the two folders
$FirstSelectedItem = gettoken("$SelectedFilesOrFolders", 1, "|");
$FolderBaseName1 = regexreplace($FirstSelectedItem, "(.*\\)(.*)", "$2");
$SecondSelectedItem = gettoken("$SelectedFilesOrFolders", 2, "|");
$FolderBaseName2 = regexreplace($SecondSelectedItem, "(.*\\)(.*)", "$2");
// First folder has to get a temp name before the real rename occurs
$TempFolderBaseName1 = ~TempFolderName1;
$NewFirstSelectedItem = $CurrentPath . "\" . $TempFolderBaseName1;
// Rename them
rename s, "$FolderBaseName1/$TempFolderBaseName1", , "$FirstSelectedItem";
rename s, "$FolderBaseName2/$FolderBaseName1", , "$SecondSelectedItem";
rename s, "$TempFolderBaseName1/$FolderBaseName2", , "$NewFirstSelectedItem";
}
One of my scripts helped you out? Please donate via Paypal
-
admin
- Site Admin
- Posts: 66362
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: Swap file names -- don't swap extensions?
This makes some sense. Maybe I do something later. Actually I never got much feedback on the swap function (although myself I use it quite often -- always on files with same extension I think).myrnalarson wrote:With version 9.90.1000 when swapping the names of 2 files, you are allowed to select files with different extensions. The swap includes the extension. Can this be changed to leave the extension alone, as most of the options on the Rename Special menu do?
FAQ | XY News RSS | XY X
-
TheQwerty
- Posts: 4373
- Joined: 03 Aug 2007 22:30
Re: Swap file names -- don't swap extensions?
My biggest use of swap file names is actually more about swapping extensions than anything else:
file.ext <> file.ext.bak
file.ext <> file.ext.bak
-
admin
- Site Admin
- Posts: 66362
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: Swap file names -- don't swap extensions?
Using bak as extension is crime in itself of course.TheQwerty wrote:My biggest use of swap file names is actually more about swapping extensions than anything else:
file.ext <> file.ext.bak
FAQ | XY News RSS | XY X
-
j_c_hallgren
- XY Blog Master
- Posts: 5826
- Joined: 02 Jan 2006 19:34
- Location: So. Chatham MA/Clearwater FL
- Contact:
Re: Swap file names -- don't swap extensions?
It's one of the function that I LOVE in XY and use it fairly regularly, as I run a couple of log files thru a VBS creating two files from each (normal data and error data) and then need to swap the "normal" file and original input names so I can upload the trimmed log data to website.admin wrote: Actually I never got much feedback on the swap function (although myself I use it quite often -- always on files with same extension I think).
Still spending WAY TOO much time here! But it's such a pleasure helping XY be a treasure!
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.
-
myrnalarson
- Posts: 68
- Joined: 29 Apr 2011 16:46
Re: Swap file names -- don't swap extensions?
Thanks VERY MUCH for the script. I've been programming for more than 50 years, first in assembler, then Apple Basic, then DOS Basic, then Visual Basic and VBA, plus a few java script things for my sound editor, but I haven't found enough XYPlorer examples to get a handle on what Microsoft calls the "object model".highend wrote: ....I just wrote a quick and dirty script that you can use for a toolbar button or anything else that can invoke a script....
I see that from studying your script I'll be able to get started. Thanks again!
-
highend
- Posts: 14954
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: Swap file names -- don't swap extensions?
You're welcome.Thanks VERY MUCH for the script
One of my scripts helped you out? Please donate via Paypal
XYplorer Beta Club