Author Topic: Sort Music Collection Using VoiceAttack  (Read 4152 times)

cldcp00

  • Guest
Sort Music Collection Using VoiceAttack
« on: March 24, 2018, 07:49:26 AM »
I wondering if it is possible to use VoiceAttack to sort my music collection.

So for example in Windows Explorer I select a single or multiple file and Say Copy/Move To Jazz or Copy/Move Soul

This would trigger a macro to Move/Copy to a folder called Jazz etc

If this is possible could somebody point me in the right Direction.

Much Appreciated

Desmond

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Sort Music Collection Using VoiceAttack
« Reply #1 on: March 24, 2018, 03:09:26 PM »
This should do what you're describing:

[Move;Copy] [file;files] to [Smooth jazz;Lounge;Elevator music;Grindcore] [overwrite;]
Code: [Select]
Begin Text Compare : [{CMDSEGMENT:0}] Equals 'Move'
    Set Boolean [~moveFile] to True
End Condition
Set Text [~targetPath] to 'C:\{CMDSEGMENT:3}\'
Begin Text Compare : [{CMDSEGMENT:4}] Equals 'overwrite'
    Set Boolean [~forceOverwrite] to True
End Condition
Press Left Ctrl+C keys and hold for 0,06 seconds and release
Inline C# Function: Move or copy clipboard files

Where the inline C# function contains:
Code: [Select]
using System;
using System.Windows.Forms;
using System.IO;

public class VAInline
{
public void main()
{
string targetPathDir = @VA.GetText("~targetPath");

if (String.IsNullOrEmpty(targetPathDir))
{
VA.WriteToLog("Error: No target directory specified", "red");
return;
}

if (!Directory.Exists(targetPathDir))
{
VA.WriteToLog("Error: The specified target directory ('" + targetPathDir + "')does not exist", "red");
return;
}

if (!targetPathDir.EndsWith("\\"))
{
targetPathDir += "\\";
}


bool? moveFile = VA.GetBoolean("~moveFile");
bool? forceOverwrite = VA.GetBoolean("~forceOverwrite");
if (forceOverwrite == true)
{
VA.WriteToLog("Warning: Files will be overwritten without further notice", "orange");
}
int copyCount = 0;
int moveCount = 0;

System.Collections.Specialized.StringCollection returnList = null;
if (Clipboard.ContainsFileDropList())
{
returnList = Clipboard.GetFileDropList();
}
else
{
VA.WriteToLog("Error: No files in clipboard", "red");
return;
}
foreach (string i in returnList)
{
try
{
if (!File.Exists(i))
{
VA.WriteToLog("Error: The file '" + i + "' does not exist and was not moved","red");
continue;
}
string fileName = Path.GetFileName(i);
string targetPath = targetPathDir + fileName;

if (File.Exists(targetPath))
{
if (forceOverwrite == true && moveFile == true)
{
File.Delete(targetPath);
}
else
{
VA.WriteToLog("Error: The file '" + fileName + "' already exists in the target directory and was not " + ((moveFile == true) ? "moved" : "copied") ,"red");
continue;
}
}

if (moveFile != true)
{
File.Copy(i, targetPath);
copyCount++;
}
else
{
File.Move(i, targetPath);

if (File.Exists(i))
{
VA.WriteToLog("Warning: '" + i + "' still exists, check that it is not in use.", "red");
copyCount++;
}
else
{
moveCount++;
}
}

}
catch (Exception e)
{
VA.WriteToLog("The " + ((moveFile == true) ? "move" : "copy") + " operation failed: "+ e.Message, "red");
}
}

VA.WriteToLog("Operation complete" + ((moveCount != 0) ?  ", " + moveCount + " files moved" : "") + ((copyCount != 0) ?  ", " + copyCount + " files copied" : ""), "green");

Clipboard.Clear();
}
}

It'll copy the files you select to the clipboard, at which point the inline function will move or copy them to the specified directory.

Note that the target directory must exist, it will not be created for you(though you could add that feature if you want it).


In the example command,
Code: [Select]
Set Text [~targetPath] to 'C:\{CMDSEGMENT:2}\'Will be set to whatever directory you speak from the command name.

E.G. "copy file to smooth jazz" would result in "C:\smooth jazz\".

You can replace "C:\" with a different path(and you'll probably want to), E.G.
Code: [Select]
Set Text [~targetPath] to 'D:\My Files\Music\{CMDSEGMENT:2}\'

There is a reasonable amount of(user  :P) error handling in the inline function, that should be verbose enough to find out what's going wrong if it does.

iceblast

  • Sr. Member
  • ****
  • Posts: 372
Re: Sort Music Collection Using VoiceAttack
« Reply #2 on: March 24, 2018, 07:39:02 PM »
Hey Pfeil, I tried this command as well. It does work, but there seems to be a lag before the files move. Any idea why, It keeps making me think it didn't work.

You wouldn't know how to make a Inline C# Function that just puts the current directory path to the Clipboard, and also can Copy the selected file names only, not the path to the Clipboard would you? I'm having no luck founding a easy way in do either of those things. Without using a 3rd party programs as well.

Keep up the good work Pfeil! :)

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Sort Music Collection Using VoiceAttack
« Reply #3 on: March 24, 2018, 07:42:53 PM »
You wouldn't know how to make a Inline C# Function that just puts the current directory path to the Clipboard, and also can Copy the selected file names only, not the path to the Clipboard would you?

Hah, guess I do ::)


EDIT:
It does work, but there seems to be a lag before the files move. Any idea why, It keeps making me think it didn't work.
That's odd...On my machine moving is near-instant(when the operation is to the same disk), and even copying is quite fast(tested with 1.3 gigs of music).

I had but removed log output for the copy/move process where it would tell you which file it was working on; For most music files the process is so quick that it just ended up as log spam.


Do keep in mind that explorer doesn't update the file list instantly, so the files may have moved already even though they're still displayed/not yet displayed. You could try sending an F5 keypress to the window to force an update to see if that's any faster for you.
« Last Edit: March 24, 2018, 07:54:30 PM by Pfeil »

iceblast

  • Sr. Member
  • ****
  • Posts: 372
Re: Sort Music Collection Using VoiceAttack
« Reply #4 on: March 24, 2018, 08:52:09 PM »
Yeah, you were right, just had to refresh the directory, I thought I had done that though. I wouldn't have said something, but it was like 10 secs before I saw that the files had moved :) Thought there might have been a problem. :)

I've already changed the move file command to suit my needs as well. Nice little code there. :)

I hadn't checked my messages, and hadn't realize you hooked me up with some code! Thanks! It works really well, after I figured out what to do with it haha.

Though I still need something that will copy the current directories path, for where the song files are stored.
Like c:\music\Queen

Having zero luck finding a solution, that's not a 3rd party program.

Thanks for all your help Pfeil!!!! :)
« Last Edit: March 24, 2018, 09:03:12 PM by iceblast »