"Linking" file extensions together
-
rhoelzl
- Posts: 200
- Joined: 28 Dec 2009 11:20
"Linking" file extensions together
Hi,
I often have set of files that have the same filename, but a different extension. For example this often appears in photography, where I have a set of files like
DSC_1234.NEF
DSC_1234.XMP
DSC_1234.PNG
DSC_1234.JPG
DSC_1234.PSD
It would be really, really cool if XYplorer would allow to define sets of extensions (in this case the set NEF,XMP,PNG,JPG,PSD) that are "linked together" that is when one of the files is renamed, all the others will be renamed automatically while keeping their extension.
Other sets that would make sense would (BIN,CUE) or (TEX,BIB,PS,DVI,PDF) etc.
Currently, I use the batch rename feature for this, but of course that is much more complicated, especially when you have to rename many such sets of files.
Just a suggestion, but I think it would simplify not only my life...
Regards,
rh
I often have set of files that have the same filename, but a different extension. For example this often appears in photography, where I have a set of files like
DSC_1234.NEF
DSC_1234.XMP
DSC_1234.PNG
DSC_1234.JPG
DSC_1234.PSD
It would be really, really cool if XYplorer would allow to define sets of extensions (in this case the set NEF,XMP,PNG,JPG,PSD) that are "linked together" that is when one of the files is renamed, all the others will be renamed automatically while keeping their extension.
Other sets that would make sense would (BIN,CUE) or (TEX,BIB,PS,DVI,PDF) etc.
Currently, I use the batch rename feature for this, but of course that is much more complicated, especially when you have to rename many such sets of files.
Just a suggestion, but I think it would simplify not only my life...
Regards,
rh
-
calude
- Posts: 355
- Joined: 13 Aug 2008 10:16
- Location: Switzerland
- Contact:
Re: "Linking" file extensions together
would also be useful for Audio
example: wavelab files
.wav (the audio file)
.gpk (the peak display)
.MRK (markers)
Calude
example: wavelab files
.wav (the audio file)
.gpk (the peak display)
.MRK (markers)
Calude
-
Stefan
- Posts: 1360
- Joined: 18 Nov 2008 21:47
- Location: Europe
Re: "Linking" file extensions together
I don't understood what is complicated to
* select all files (Ctrl+A)
* right click and choose "Rename Special > Search&Replace"
* enter dsc_1234/NewName
* press preview?
* select all files (Ctrl+A)
* right click and choose "Rename Special > Search&Replace"
* enter dsc_1234/NewName
* press preview?
-
rhoelzl
- Posts: 200
- Joined: 28 Dec 2009 11:20
Re: "Linking" file extensions together
I don't understand this suggestion. Wouldn't this rename all files that contain the "dsc_1234" part anywhere in their name, even if these files are not part of the "set"? Also it's more complicated than using batch rename.Stefan wrote:I don't understood what is complicated to
* select all files (Ctrl+A)
* right click and choose "Rename Special > Search&Replace"
* enter dsc_1234/NewName
* press preview?
-
Stefan
- Posts: 1360
- Joined: 18 Nov 2008 21:47
- Location: Europe
Re: "Linking" file extensions together
If your other file name could contain the whole file name of the file to rename , then yes, it will.rhoelzl wrote:Wouldn't this rename all files that contain the "dsc_1234" part anywhere in their name,
even if these files are not part of the "set"?
But then you could use "RegEx rename" to match the whole string.
Just modify the parts in blue color:
^dsc_1234(\.\w{3,})$ > New Name$1
RegEx online tester: http://rereplace.com/
To make this more easy you could use an script which do this for you in the back ground.
Here is an example script (if one like to test, test with test files first)
Save this script as "Rename_FileSet.xys" into your XY\Scripts folder:
Rename_FileSet.xys
Code: Select all
/*
XYSName: Rename_FileSet.xys
Purpose: Rename all file with same base name, regardless the file extension,
to an new base name, leaving the original extension in place.
License: Free for all, but without any warranty - use with tryout copies of your real files first!!!
Date Version Description
2010.03.05 001 First test
2010.03.05 002 Added Preview function
*/
//"Rename Set"
$Files = getinfo("SelectedItemsNames", "|");
$CurBase = "<curbase>";
$HTML = utf8decode(urldecode(html('<HTML>
<BODY>
Purpose: Rename all file with same base name, regardless the file extension.<BR>
1. Select first file with name to replace (or type base name yourself)<BR>
2. Press Ctrl+A to select ALL files<BR>
3. Execute this script<BR>
4. Modify New Name<BR>
5. Press Rename button<BR>
<FORM method="GET" action="xys:">
Base name: <input type="text" name="bname" size="50" Value="'. $CurBase .'">
(without extension) <BR>
New name: <input type="text" name="nname" size="50" Value="'. $CurBase .'">
(without extension) <BR> <BR><BR>
<INPUT type="submit" name="Submit" value="Rename" >
<INPUT type="submit" name="Preview728" value="Preview" >
<input type="submit" name="Cancel728" value="Cancel">
</FORM>
</BODY>
</HTML>',"700", "375", "Rename File sets")));
$Cancel = strpos($HTML, "Cancel728=Cancel");
end ($Cancel > 0) ;
end ("$HTML"=="");
substr $HTML, $HTML, 1;
//text $HTML;
$CurBase = gettoken($HTML, "1", "&");
$CurBase = gettoken($CurBase, 2, "=");
end ("$CurBase"==""), "Base name pattern missing";
$NewName = gettoken($HTML, "2", "&");
$NewName = gettoken($NewName, 2, "=");
end ("$NewName"==""), "New name pattern missing";
end ("$CurBase"=="$NewName"), "Using same pattern for both makes no sense";
$Preview = "";
$count = 1;
while (true){
$file = gettoken($Files, $count, "|");
If ($file=="") {break;}
$filebase = regexreplace($file,"^(.+[^.])(\..+)$","$1");
If ($filebase!=$CurBase) {incr $count; continue;}
$fileext = regexreplace($file,"^(.+[^.])(\..+)$","$2");
IF (strpos($HTML, "Preview728=Preview") > 0){
$Preview = $Preview . $NewName$fileext . "<crlf>";
}else{
rename r, "$file > $NewName$fileext";
}
incr $count;
}
IF (strlen($Preview)>0){
text $Preview;
setting AllowRecursion;
self $ScriptFile, file;
Load $ScriptFile;}
Script Preview
HTH?
Thanks to Don for implementing HTML();
To see the attached files, you need to log into the forum.
-
rhoelzl
- Posts: 200
- Joined: 28 Dec 2009 11:20
Re: "Linking" file extensions together
Hi Stefan,
Sorry that I haven't answered much earlier. The script appeared to be a rather clumsy solution compared to really ALWAYS linking extensions together.
But since that latter thing does not seem to be coming I would like to work with your script to make it as user friendly as possible.
What I couldn't figure out: Is there any way to avoid having to press CTRL-A? It should just apply to all files (with the right basename) in the current directory. Could you tell me what needs to be modified?
Thanks!
Sorry that I haven't answered much earlier. The script appeared to be a rather clumsy solution compared to really ALWAYS linking extensions together.
But since that latter thing does not seem to be coming I would like to work with your script to make it as user friendly as possible.
What I couldn't figure out: Is there any way to avoid having to press CTRL-A? It should just apply to all files (with the right basename) in the current directory. Could you tell me what needs to be modified?
Thanks!
-
Stefan
- Posts: 1360
- Joined: 18 Nov 2008 21:47
- Location: Europe
Re: "Linking" file extensions together
Since you talk about renaming:
rhoelzl> "when one of the files is renamed, all the others will be renamed automatically while keeping their extension."
rhoelzl> "Currently, I use the batch rename feature for this,"
then batch renaming seams to be an good solution. (and my script is nonsense)
FROM:
DSC_1234.NEF
DSC_1234.XMP
DSC_1234.PNG
DSC_1234.JPG
DSC_1234.PSD
TO:
New Name DSC_1234.JPG
New Name DSC_1234.NEF
New Name DSC_1234.PNG
New Name DSC_1234.PSD
New Name DSC_1234.XMP
DO:
- Press Ctrl+A (To select all files in your case)
- press Shift+F2 to call "batch rename" (depends on XY version and settings)
- enter new name (and "*" if wanted to keep the old name)
- done
Or would you want to use this "FileSet"-feature for other purposes too?
Then you may post (IMO) more usage examples so Don can see the benefit.
Did that help?
rhoelzl> "when one of the files is renamed, all the others will be renamed automatically while keeping their extension."
rhoelzl> "Currently, I use the batch rename feature for this,"
then batch renaming seams to be an good solution. (and my script is nonsense)
FROM:
DSC_1234.NEF
DSC_1234.XMP
DSC_1234.PNG
DSC_1234.JPG
DSC_1234.PSD
TO:
New Name DSC_1234.JPG
New Name DSC_1234.NEF
New Name DSC_1234.PNG
New Name DSC_1234.PSD
New Name DSC_1234.XMP
DO:
- Press Ctrl+A (To select all files in your case)
- press Shift+F2 to call "batch rename" (depends on XY version and settings)
- enter new name (and "*" if wanted to keep the old name)
- done
Or would you want to use this "FileSet"-feature for other purposes too?
Then you may post (IMO) more usage examples so Don can see the benefit.
DELETED (see below)rhoelzl wrote: What I couldn't figure out: Is there any way to avoid having to press CTRL-A? It should just apply to all files (with the right basename) in the current directory. Could you tell me what needs to be modified?
Thanks!
Did that help?
Last edited by Stefan on 25 Aug 2010 13:06, edited 1 time in total.
-
Stefan
- Posts: 1360
- Joined: 18 Nov 2008 21:47
- Location: Europe
Re: "Linking" file extensions together
Now i see and understood. Yes, this should be possible... i will update this later.Stefan wrote:rhoelzl wrote: What I couldn't figure out: Is there any way to avoid having to press CTRL-A? It should just apply to all files (with the right basename) in the current directory. Could you tell me what needs to be modified?
Thanks!
-
Stefan
- Posts: 1360
- Joined: 18 Nov 2008 21:47
- Location: Europe
Re: "Linking" file extensions together
Please try if this is what you want:Stefan wrote:Since you talk about renaming:
rhoelzl> "when one of the files is renamed, all the others will be renamed automatically while keeping their extension."
rhoelzl> "Currently, I use the batch rename feature for this,"
then batch renaming seams to be an good solution. (and my script is nonsense)
FROM:
DSC_1234.NEF
DSC_1234.XMP
DSC_1234.PNG
DSC_1234.JPG
DSC_1234.PSD
TO:
New Name DSC_1234.JPG
New Name DSC_1234.NEF
New Name DSC_1234.PNG
New Name DSC_1234.PSD
New Name DSC_1234.XMP
DO:
- Press Ctrl+A (To select all files in your case)
- press Shift+F2 to call "batch rename" (depends on XY version and settings)
- enter new name (and "*" if wanted to keep the old name)
- done
Code: Select all
//1) select one of the files with the common base name
//2) execute this script
$BaseName = "<curbase>"; //get current basename into an var
selfilter """$BaseName*"""; //select all files with the same base name + dot + any extension
#121; //call native XY -Batch rename feature
//3) enter an renaming pattern and press OK-
rhoelzl
- Posts: 200
- Joined: 28 Dec 2009 11:20
Re: "Linking" file extensions together
Excellent, thank you.
I made this into a very easy to use "portable open with" command:
I made this into a very easy to use "portable open with" command:
Code: Select all
|"Rename file set ''<curbase>.*''" *>::$BaseName = "<curbase>";selfilter """$BaseName*""";#121;-
Stefan
- Posts: 1360
- Joined: 18 Nov 2008 21:47
- Location: Europe
Re: "Linking" file extensions together
OK, fine!
Note: since we didn't need to use this $Var in this simple case, we can drop it too:
And since it is an file set *I* would drop this ".*" random extension of the description and useBut this belongs to you, since it's your script.
Note: since we didn't need to use this $Var in this simple case, we can drop it too:
Code: Select all
|"Rename file set ''<curbase>.*''" *>::selfilter """<curbase>*""";#121;And since it is an file set *I* would drop this ".*" random extension of the description and use
Code: Select all
|"Rename file set ''<curbase>''" *>::selfilter """<curbase>*""";#121;-
rhoelzl
- Posts: 200
- Joined: 28 Dec 2009 11:20
Re: "Linking" file extensions together
Hmm, I tried to improve the filtering by changing it into
(aim: really only ignore extension), but it does not select anything... any ideas?
EDIT: changed the first "." into "\\." Also, $Basename would have to be escaped...
Code: Select all
selfilter """>" . $BaseName . "\\.[^\\.]*""";EDIT: changed the first "." into "\\." Also, $Basename would have to be escaped...
-
Stefan
- Posts: 1360
- Joined: 18 Nov 2008 21:47
- Location: Europe
Re: "Linking" file extensions together
1.) I don't understood what you want:rhoelzl wrote:Hmm, I tried to improve the filtering by changing it into
(aim: really only ignore extension), but it does not select anything... any ideas?Code: Select all
selfilter """>" . $BaseName . "\\.[^\\.]*""";
EDIT: changed the first "." into "\\." Also, $Basename would have to be escaped...
"<curbase>" is already the file name without the-last-dot-and-following-signs ("the extension")
2.) please take an look into the help "Adv Topics > Scripting Commands Ref > selfilter", selfilter has no RegEx feature as far as i see.
-
rhoelzl
- Posts: 200
- Joined: 28 Dec 2009 11:20
Re: "Linking" file extensions together
1.) Yes but if Blabla.txt is selected, then the filter "<curbase>*" would, e.g., also match Blabla.Blublu.txt
2.) Hmm okay, thanks. I assumed that it should have that feature, because the "Edit -> Select -> Selection Filter" feature DOES have regexp.
2.) Hmm okay, thanks. I assumed that it should have that feature, because the "Edit -> Select -> Selection Filter" feature DOES have regexp.
-
TheQwerty
- Posts: 4373
- Joined: 03 Aug 2007 22:30
Re: "Linking" file extensions together
I've always found SelFilter to be extremely frustrating since it lacks regex support.
I suggest using the single character wildcard '?' as in:Now the new problem is matching extensions which are not 3 characters, so you might want to add a 4 character pattern to this as well using:That should cover most cases, but you could always use a while loop and StrRepeat to generate a pattern that would handle 0 through n-character extensions.
Hope that helps!
I suggest using the single character wildcard '?' as in:
Code: Select all
selfilter "$BaseName.???";Code: Select all
selfilter "$BaseName.???|$BaseName.????";Hope that helps!
XYplorer Beta Club