Script: Shortcut all files with chosen tags to my folder

Discuss and share scripts and script files...
Post Reply
mancos
Posts: 7
Joined: 23 Aug 2011 17:54

Script: Shortcut all files with chosen tags to my folder

Post by mancos »

Hey, does anybody know if such a script already exists, or could someone help me create one?

What I'm looking for is a script that allows me with a click (or automatically) to make a shortcut of all files with say the tag 'food' to my folder: "cooking".

Thanks in advance

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

Re: Script: Shortcut all files with chosen tags to my folder

Post by highend »

Get e.g. xxmklink from http://www.xxcopy.com/xxcopy38.htm and modify the variables in the script (e.g. $linkcmd, $destdir and $sourcedir).

Quick and dirty:

Code: Select all

// Create symbolic links
// xxmklink can be found here: http://www.xxcopy.com/xxcopy38.htm
// ::load "<xyscripts>\.Test.xys";

	$tag = "[food]";
	$lnk = ".lnk";
	$linkcmd = quote("D:\Temp\Cooking\xxmklink.exe");
	$destdir = "D:\Temp\Cooking";
	$sourcedir = "<curpath>";
	$tmpbatchfile = "%temp%\~xxmklink.bat";

	$files = folderreport("files:{fullname}[{Comment}]", "r", "$sourcedir", "r");

	writefile("$tmpbatchfile", "@Echo off".<crlf>, o, ta);

	$result = "";
	foreach($item, $files, "<crlf>") {
		if($item == "") { break; }
		$found = strpos("$item", "$tag", , 0);
		if($found != -1) {
			$newfilename = replace("$item", "$tag", "");
			$onlybasename = regexreplace("$newfilename", ".*\\", "");
			$onlybasename = regexreplace("$onlybasename", "(.*(?=\.))(.*)", "$1");
			$lnkfile = quote($destdir . "\" . $onlybasename . $lnk);
			writefile("$tmpbatchfile", "$linkcmd " . $lnkfile . " " . quote($newfilename).<crlf>, a, ta);
		}
	}
	open "$tmpbatchfile";
One of my scripts helped you out? Please donate via Paypal

mancos
Posts: 7
Joined: 23 Aug 2011 17:54

Re: Script: Shortcut all files with chosen tags to my folder

Post by mancos »

Wow, thanks a lot for this! But it looks more complicated than I thought it would be.

The first problem I came across with is that xxmklink automatically closes as soon as I press any keyboard button, including space to show more commands.

I've also never come across symbolic links. I need to create a file in the directory I want it to be sent or from where it links? And what kind of file with what information? Or does xxmklink create it for me when I write the command?

I have to admit I never went beyond html and custom scripting. So no idea of batch files etc.

If you think it's too much to explain, never mind, I'll just try to find another way. But of course I would really appreciate further explanation.

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

Re: Script: Shortcut all files with chosen tags to my folder

Post by highend »

The first problem I came across with is that xxmklink automatically closes as soon as I press any keyboard button, including space to show more commands.
Mh? xxmklink is a program that's meant to be executed from a command prompt / batch file.

Code: Select all

I've also never come across symbolic links. I need to create a file in the directory I want it to be sent or from where it links? And what kind of file with what information?
Sorry, I don't understand (your english).

The code snippet creates a temporary batch file and writes all xxmklink commands to it. I could just execute it directly in the while loop but it would pop up a lot of command prompt windows (depending on how many symlinks have to be created), so it's better to only open one command prompt that executes all xxmklink statements.
One of my scripts helped you out? Please donate via Paypal

mancos
Posts: 7
Joined: 23 Aug 2011 17:54

Re: Script: Shortcut all files with chosen tags to my folder

Post by mancos »

Okay, I got it all sorted and working now.

I thought I had to create some additional files, but eventually I realised I just had to copy it all into one .xys file and run that.

Again, much appreciated!

Post Reply