Sorting Audio Files Into Folder Script
Sorting Audio Files Into Folder Script
Hi There,
I am new to Xyplorer and scripting and I just wanted to know it capabilities.
My situation is that I have many thousands of audio files that need to be sorted into folders so I have to visually look at the file name and drag them or cut and paste them into the relevant folder.
So I was wondering is it possible that I could have a shortcut key or a button that when triggered would present the user with a list of target folders then clicking on one of the folders would cause the script to copy/move to that folder
Is this possible and it it is could somebody point me in the right directions as to how this could be done
Thanks in advance for any help.
I am new to Xyplorer and scripting and I just wanted to know it capabilities.
My situation is that I have many thousands of audio files that need to be sorted into folders so I have to visually look at the file name and drag them or cut and paste them into the relevant folder.
So I was wondering is it possible that I could have a shortcut key or a button that when triggered would present the user with a list of target folders then clicking on one of the folders would cause the script to copy/move to that folder
Is this possible and it it is could somebody point me in the right directions as to how this could be done
Thanks in advance for any help.
Re: Sorting Audio Files Into Folder Script
Set your destination folders in the script first, one line for each folder.
Select one file, run the script once. Click outside the menu! but remember where it popped up.
Change the two position variables to better fit your needs.
Select one file, run the script once. Click outside the menu! but remember where it popped up.
Change the two position variables to better fit your needs.
Code: Select all
$moveItem = 0; // 0 = Copy item, 1 = Move item
$menuPosX = 500;
$menuPosY = 500;
$destinations = <<<>>>
C:\Temp
D:\Temp
>>>;
$selected = <get SelectedItemsPathNames>;
end (!$selected), "No item(s) selected, aborted!";
setting "BackgroundFileOps", 0;
foreach($item, $selected, <crlf>, "e") {
$base = gpc($item, "file");
$menu = <<<>>>
$base||$item|4
-
$destinations
>>>;
$menu = regexreplace($menu, "^[ \t]+");
$target = popupmenu($menu, $menuPosX, $menuPosY, 6:=<crlf>, 7:="|");
if (!$target) { continue; }
copyto $target, $item, , 2, 2, 2, 1, 0, 0, 1, 0, 0;
if ($moveItem == 1) { runret(lax("cmd" /c DEL /F /Q "$item"), "%TEMP%"); }
}
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de
-
- Site Admin
- Posts: 59751
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: Sorting Audio Files Into Folder Script
This (manually sorting a bunch of files into a set of folders) seems to be a common task, and I'm getting some ideas on how to streamline it in an elegant way (see viewtopic.php?t=26566).
Your destination folders, where are they? Is there a deep hierarchy of folders?
Your destination folders, where are they? Is there a deep hierarchy of folders?
FAQ | XY News RSS | XY Twitter
Re: Sorting Audio Files Into Folder Script
Generally there would be no more that 4 level
Top level Music Library
level 2 Genre
level 3 Artist
level 4 Year
But solution should be able to move / copy file to any where on the pc
Top level Music Library
level 2 Genre
level 3 Artist
level 4 Year
But solution should be able to move / copy file to any where on the pc
Re: Sorting Audio Files Into Folder Script
Thank you very much for this script. I will make a donation when I have the funds thanks again - cldcp00highend wrote: ↑30 Aug 2023 08:17 Set your destination folders in the script first, one line for each folder.
Select one file, run the script once. Click outside the menu! but remember where it popped up.
Change the two position variables to better fit your needs.
Code: Select all
$moveItem = 0; // 0 = Copy item, 1 = Move item $menuPosX = 500; $menuPosY = 500; $destinations = <<<>>> C:\Temp D:\Temp >>>; $selected = <get SelectedItemsPathNames>; end (!$selected), "No item(s) selected, aborted!"; setting "BackgroundFileOps", 0; foreach($item, $selected, <crlf>, "e") { $base = gpc($item, "file"); $menu = <<<>>> $base||$item|4 - $destinations >>>; $menu = regexreplace($menu, "^[ \t]+"); $target = popupmenu($menu, $menuPosX, $menuPosY, 6:=<crlf>, 7:="|"); if (!$target) { continue; } copyto $target, $item, , 2, 2, 2, 1, 0, 0, 1, 0, 0; if ($moveItem == 1) { runret(lax("cmd" /c DEL /F /Q "$item"), "%TEMP%"); } }
Re: Sorting Audio Files Into Folder Script
Hi
I decided to add an audit trail to your code but for some reason it is not working, could you point me in the right direction please.
I decided to add an audit trail to your code but for some reason it is not working, could you point me in the right direction please.
Code: Select all
$moveItem = 0; // 0 = Copy item, 1 = Move item
$menuPosX = 500;
$menuPosY = 500;
$auditTrailFile = "D:\New Music Library\0000 Music Files Library & Information\Xyplorer Music File Audit.txt"; // Set the path to your audit trail file.
$destinations = <<<>>>
D:\New Music Library\New Music Library 2020\Dance
D:\New Music Library\New Music Library 2020\Country
D:\New Music Library\New Music Library 2020\Classical
>>>;
$selected = <get SelectedItemsPathNames>;
end (!$selected), "No item(s) selected, aborted!";
setting "BackgroundFileOps", 0;
foreach($item, $selected, <crlf>, "e") {
$base = gpc($item, "file");
$menu = <<<>>>
$base||$item|4
-
$destinations
>>>;
$menu = regexreplace($menu, "^[ \t]+");
$target = popupmenu($menu, $menuPosX, $menuPosY, 6:=<crlf>, 7:="|");
if (!$target) { continue; }
copyto $target, $item, , 2, 2, 2, 1, 0, 0, 1, 0, 0;
// Log the operation to the audit trail file.
$auditLog = "Copied: " + $item + " to: " + $target + "\n";
appendfile $auditTrailFile, $auditLog;
if ($moveItem == 1) { runret(lax("cmd" /c DEL /F /Q "$item"), "%TEMP%"); }
}
-
- Site Admin
- Posts: 59751
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: Sorting Audio Files Into Folder Script
Strings are concatenated with
.
, not with +
.FAQ | XY News RSS | XY Twitter
Re: Sorting Audio Files Into Folder Script
...and in double quotes variables are resolved, so you can change:
Only thing to look for: the character following the variable name must be non-allowed in names.
Code: Select all
// $auditLog = "Copied: " + $item + " to: " + $target + "\n"; // can be changed to:
$auditLog = "Copied: $item to: $target\n"; // for me this looks better!
W7(x64) SP1 German
( +WXP SP3 )
( +WXP SP3 )
Re: Sorting Audio Files Into Folder Script
Replace
with
and after the loop a
Code: Select all
$auditLog = "Copied: " + $item + " to: " + $target + "\n";
appendfile $auditTrailFile, $auditLog;
Code: Select all
$auditLog .= "Copied: $item to: $target<crlf>";
Code: Select all
writefile($auditTrailFile, $auditLog);
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de
Re: Sorting Audio Files Into Folder Script
Hi Highend,
I think I have amended the code as you has suggested (see below) but the script still will not run, Vert sorry if I am doing something silly.
I think I have amended the code as you has suggested (see below) but the script still will not run, Vert sorry if I am doing something silly.
Code: Select all
$moveItem = 0; // 0 = Copy item, 1 = Move item
$menuPosX = 500;
$menuPosY = 500;
$auditTrailFile = "D:\New Music Library\0000 Music Files Library & Information\Xyplorer Music File Audit.txt"; // Set the path to your audit trail file.
$destinations = <<<>>>
D:\New Music Library\New Music Library 2020\Dance
D:\New Music Library\New Music Library 2020\Country
D:\New Music Library\New Music Library 2020\Classical
>>>;
$selected = <get SelectedItemsPathNames>;
end (!$selected), "No item(s) selected, aborted!";
setting "BackgroundFileOps", 0;
foreach($item, $selected, <crlf>, "e") {
$base = gpc($item, "file");
$menu = <<<>>>
$base||$item|4
-
$destinations
>>>;
$menu = regexreplace($menu, "^[ \t]+");
$target = popupmenu($menu, $menuPosX, $menuPosY, 6:=<crlf>, 7:="|");
if (!$target) { continue; }
copyto $target, $item, , 2, 2, 2, 1, 0, 0, 1, 0, 0;
// Log the operation to the audit trail file.
$auditLog .= "Copied: $item to: $target<crlf>";
if ($moveItem == 1) { runret(lax("cmd" /c DEL /F /Q "$item"), "%TEMP%"); }
}
writefile($auditTrailFile, $auditLog);
Re: Sorting Audio Files Into Folder Script
You have removed the indenting, make it match the original, also you might want to add the "a" flag to writefile, else you will lose your log after each run.
Re: Sorting Audio Files Into Folder Script
Hi Jupe
Thanks for you help, i am still leaning.
Are you saying that indenting the last line will make it work?
line of code
writefile($auditTrailFile, $auditLog);
Also
Not sure what you mean sorry
also you might want to add the "a" flag to writefile, else you will lose your log after each run
Thanks for you help, i am still leaning.
Are you saying that indenting the last line will make it work?
line of code
writefile($auditTrailFile, $auditLog);
Also
Not sure what you mean sorry
also you might want to add the "a" flag to writefile, else you will lose your log after each run
Re: Sorting Audio Files Into Folder Script
No not just the last line, I said make the indenting (of the whole script) match the original, also indent the writefile line to match the indent of the curly brace above it. Indenting is important.
Lookup the writefile command in the help file, where you will see you require "a", as the third parameter.
Also since you didn't initialize $auditLog var you will have that text prefixed to each log entry, init the var like this
Lookup the writefile command in the help file, where you will see you require "a", as the third parameter.
Also since you didn't initialize $auditLog var you will have that text prefixed to each log entry, init the var like this
$auditLog = "";
at the start of your script to avoid this.Re: Sorting Audio Files Into Folder Script
But be careful: this regards all *executable* lines...
... but <<<>>> begins a group of text lines (up to >>>) - so it must be:
... but <<<>>> begins a group of text lines (up to >>>) - so it must be:
Code: Select all
$destinations = <<<>>>
D:\New Music Library\New Music Library 2020\Dance
D:\New Music Library\New Music Library 2020\Country
D:\New Music Library\New Music Library 2020\Classical
>>>;
W7(x64) SP1 German
( +WXP SP3 )
( +WXP SP3 )
Re: Sorting Audio Files Into Folder Script
Yep, that's why I said "match the original", but in this use case it wouldn't matter if that section was indented anyway, because any extraneous spaces would get removed by running the script.