Page 1 of 2

Tags from folder names

Posted: 09 Aug 2012 11:40
by kiwichick
Hi there, I'm really loving XYplorer for its ability to tag folders and files. I can finally get my stuff organised in ways that make sense to me. YAY!!!! However, having thousands of files to tag, the initial tagging process is going to be very time consuming - so I'm wondering if, as a place to start (and cut down some of the time), there is a way I can tag files from the names of the folders they're in? And, as a step further, is there a way to 'automatically' tag files with the name of the folder they are added to? Thanks for any help, from De.

Re: Tags from folder names

Posted: 09 Aug 2012 11:51
by admin
Hi and welcome!

I'm not sure if that is a good strategy. The folder tree itself is great way to organize stuff if used with smartness. The tagging should rather work across the folder tree. Mirroring it in the way you describe is not effective. You will get redundant information and ultimately too many tags, which will create just a new type of chaos and at some point slow down the app.

Don

Re: Tags from folder names

Posted: 09 Aug 2012 13:17
by kiwichick
Hi 'admin' and thanks for the welcome!!! So are you saying it can't be done? I appreciate the advise and I understand the reasons you state. But I also have reasons for wanting to do it. For example, I have thousands of images whose current folder names are based on the description of the photos eg: blue shirt, canon, white fur coat, golf course. I want them tagged by these descriptions because, ultimately, they will be moved to new folders with names based on the occasion the photos were taken. And I want them to retain the original 'description' tags because, although they will be grouped together differently, I will still be able to search for photos based on the same description. I hope that makes sense :biggrin: Cheers from De.

Re: Tags from folder names

Posted: 09 Aug 2012 14:40
by admin
kiwichick wrote:Hi 'admin' and thanks for the welcome!!! So are you saying it can't be done? I appreciate the advise and I understand the reasons you state. But I also have reasons for wanting to do it. For example, I have thousands of images whose current folder names are based on the description of the photos eg: blue shirt, canon, white fur coat, golf course. I want them tagged by these descriptions because, ultimately, they will be moved to new folders with names based on the occasion the photos were taken. And I want them to retain the original 'description' tags because, although they will be grouped together differently, I will still be able to search for photos based on the same description. I hope that makes sense :biggrin: Cheers from De.
Ah, I see! Now that makes total sense and it surely can be done using scripting. I hope some of the scripters here read this... ;) ...

Re: Tags from folder names

Posted: 09 Aug 2012 14:57
by Stefan
Simplest method:

* Select some/all files
* copy the code into the XY address bar
* press <ENTER>

Code: Select all

::tag "I'am from <curfolder>",,2;
To remove comments use

Code: Select all

::tag ,,2;
- - -

@Don, FYI:
This doesn't work as i would though with "Edit > Show All Items In Branch".
Always the top level folder's name is used for the comment string.


- - -


EDITed since "comment" is depreciated

Code: Select all

::comment "I'am from <curfolder>";
.

Re: Tags from folder names

Posted: 09 Aug 2012 15:20
by highend
If you want to completely automate this task (beside pushing of a button), should files just get their parent folder name as the tag?

E.g.

D:\Music\song_A.mp3
-> Tag: Music

D:\Music\Soul\song_B.mp3
-> Tag: Soul

etc. ?

Re: Tags from folder names

Posted: 10 Aug 2012 01:25
by kiwichick
Thanks Stefan, It works but I would like to add 'tags' not 'comments'.
Stefan wrote:Simplest method:

* Select some/all files
* copy the code into the XY address bar
* press <ENTER>

Code: Select all

::tag "I'am from <curfolder>",,2;
To remove comments use

Code: Select all

::tag ,,2;
- - -

@Don, FYI:
This doesn't work as i would though with "Edit > Show All Items In Branch".
Always the top level folder's name is used for the comment string.


- - -


EDITed since "comment" is depreciated

Code: Select all

::comment "I'am from <curfolder>";
.

Re: Tags from folder names

Posted: 10 Aug 2012 01:39
by kiwichick
Thanks highend, Yes the parent folder name would be great. Although having a separate task to add the 'parent of the parent' would be even more great!! Occasionally the files are in subfolders and the subfolder name isn't relevant.

So with your example I would like:

D:\Music\Soul\song_B.mp3
-> Tag: Soul

But, if possible, also this:

D:\Music\Soul\song_B.mp3
-> Tag: Music

And maybe even both in the same task:
D:\Music\Soul\song_B.mp3
-> Tag: Soul; Music
highend wrote:If you want to completely automate this task (beside pushing of a button), should files just get their parent folder name as the tag?

E.g.

D:\Music\song_A.mp3
-> Tag: Music

D:\Music\Soul\song_B.mp3
-> Tag: Soul

etc. ?

Re: Tags from folder names

Posted: 14 Aug 2012 23:47
by kiwichick
Hi there, I'm still looking for help with this if there's anyone out there who may have suggestions for this. PLEASE help make my tagging job easier!!! :biggrin:

Re: Tags from folder names

Posted: 19 Aug 2012 13:31
by highend
Ok, thanks to Don for implementing the new command "getPathComponent" and because of this, tagging your files with foldernames is only a matter of a few lines of code.

Here we go:

1.) Select all files that should be tagged
2.) Run the script

Code: Select all

/* 19.08.2012, Tag files with their parent (grandparent etc.) folder names
   v11.40.0204 or up is required for "getpathcomponent"
   ::load "<xyscripts>\TagFiles.xys";
*/

	$firstParent = getpathcomponent(<curpath>, "component", -1);
	$secondParent = getpathcomponent(<curpath>, "component", -2);

	$folderNames = "+" . $firstParent . "|" . "+" .$secondParent;

	$tags = inputselect("Select all foldernames that should be used as tags for the current file selection:", $folderNames, "|", 2); // Let's choose which foldernames should be written as tags
	$tags = replace($tags, "|", ",");
	end ($tags == ""), "No tag(s) selected, aborted!";
	end (getinfo("CountSelected") < 1), "No file(s) selected, aborted!";

	tag $tags, , 1, 1; // Replace current tags with selected folder names as (new) tags

Re: Tags from folder names

Posted: 19 Aug 2012 13:34
by admin
BTW: Of course it was actually this thread that inspired me to add getPathComponent. :)

Re: Tags from folder names

Posted: 19 Aug 2012 13:45
by highend
admin wrote:BTW: Of course it was actually this thread that inspired me to add getPathComponent. :)
What else :)

And ofc I was too lazy to think about a function that extracts all path components...

Btw: Is there an easy way to return the number of folders in a path? Would help if someone (me) wants to iterate through them.

Code: Select all

$a = "C:\Documents and Settings\Administrador\Meus documentos\XYplorer\Contas a receber.docx.bak";
msg getpathcomponent($a, "component", 0);
Would return: 4

Re: Tags from folder names

Posted: 19 Aug 2012 13:56
by admin
Hey, cool idea! Finally a good usage for 0. Although ... "component", "count") is maybe more intuitive...

Re: Tags from folder names

Posted: 20 Aug 2012 01:46
by kiwichick
Thanks guys, I don't have that version of XYplorer so I can't check it but I'm glad I've been an 'inspiration' for adding a new component :biggrin:

Re: Tags from folder names

Posted: 20 Aug 2012 06:49
by kiwichick
So I've installed the latest beta and the script works - yay! The popup window to select the tags is cool. It tags only selected items which is OK, but when I select a folder I generally want to tag its contents as well, as deep as any subfolders might go - maybe the popup window could have some extra options to "Tag folder" or "Tag folder and contents"? And I also generally want it to add tags not replace existing tags - maybe more options to "Replace tags" or "Add tags"? Thanks for any thoughts.