Tags from folder names

Discuss and share scripts and script files...
kiwichick
Posts: 557
Joined: 08 Aug 2012 04:14
Location: Pahiatua, New Zealand

Tags from folder names

Post 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.
Windows 10 Pro 22H2

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

Re: Tags from folder names

Post 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

kiwichick
Posts: 557
Joined: 08 Aug 2012 04:14
Location: Pahiatua, New Zealand

Re: Tags from folder names

Post 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.
Windows 10 Pro 22H2

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

Re: Tags from folder names

Post 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... ;) ...

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Tags from folder names

Post 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>";
.

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

Re: Tags from folder names

Post 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. ?
One of my scripts helped you out? Please donate via Paypal

kiwichick
Posts: 557
Joined: 08 Aug 2012 04:14
Location: Pahiatua, New Zealand

Re: Tags from folder names

Post 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>";
.
Windows 10 Pro 22H2

kiwichick
Posts: 557
Joined: 08 Aug 2012 04:14
Location: Pahiatua, New Zealand

Re: Tags from folder names

Post 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. ?
Windows 10 Pro 22H2

kiwichick
Posts: 557
Joined: 08 Aug 2012 04:14
Location: Pahiatua, New Zealand

Re: Tags from folder names

Post 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:
Windows 10 Pro 22H2

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

Re: Tags from folder names

Post 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
Last edited by highend on 19 Aug 2012 23:37, edited 1 time in total.
One of my scripts helped you out? Please donate via Paypal

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

Re: Tags from folder names

Post by admin »

BTW: Of course it was actually this thread that inspired me to add getPathComponent. :)

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

Re: Tags from folder names

Post 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
One of my scripts helped you out? Please donate via Paypal

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

Re: Tags from folder names

Post by admin »

Hey, cool idea! Finally a good usage for 0. Although ... "component", "count") is maybe more intuitive...

kiwichick
Posts: 557
Joined: 08 Aug 2012 04:14
Location: Pahiatua, New Zealand

Re: Tags from folder names

Post 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:
Windows 10 Pro 22H2

kiwichick
Posts: 557
Joined: 08 Aug 2012 04:14
Location: Pahiatua, New Zealand

Re: Tags from folder names

Post 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.
Windows 10 Pro 22H2

Post Reply