Random Music Copier

Discuss and share scripts and script files...
Post Reply
serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

Random Music Copier

Post by serendipity »

I had a very simple "Random file selector" script before "the_hyrax_lord" posted a request here. I adapted that to write this script with more options.

//Random Music Copier
/*
How it works:
-Copies user-defined random (shuffled) music to another location (E.g. USB stick)
-Remembers previous list of files, so that you don't copy same files.
How? Using comments, Copied/Uncopied files are marked as "Copied"/"NotCopied" respectively.
-Option to delete older files from destination before copying new set of random files.

WARNING: Since it uses comments you will lose your old comments from source folder. Check this before you use.
*/
RandomMusicCopier.xys

Code: Select all

//Random Music Copier
/*
How it works:
-Copies user-defined random (shuffled) music to another location (E.g. USB stick)
-Remembers previous list of files, so that you don't copy same files.
 How? Using comments, Copied/Uncopied files are marked as "Copied"/"NotCopied" respectively. 
-Option to delete older files from destination before copying new set of random files.

WARNING: Since it uses comments you will lose your old comments from source folder. Check this before you use. 
*/

//Music to copy to (don't add trailing \)
  $MusicDestination="D:\newlocation";
//Music to copy from (don't add trailing \)
  $MusicSource="D:\Music";
//Song extensions. Add more extensions (separated by ;) if you want.
  $MusicExtensions= "*.mp3;*.ogg";
//Set random number of files to copy
  $RandomNumber=20;
  
//Option to delete old files from Music destination before copying new ones
  IF (confirm ("Delete files in ""$MusicDestination\"" first?<crlf><crlf>OK=Delete files.<crlf>Cancel=Keep files.")==1){
//Delete by moving files into recycle bin but without any prompt
  delete 1,0, "$MusicDestination\*";
  }
  ELSE{
//nothing
  }

//Show files in music source folder and all its branches 
  goto "$MusicSource\?$MusicExtensions /r";

//Filter previously copied files
  selfilter """Copied""", ,"comment";
//Invert selection
  #252;
//Comment files as NotCopied
  comment NotCopied;
//Show all files "NotCopied" files
  goto "$MusicSource\?comment:NotCopied /r";
//Above code can be improved if XY allowed this: goto "$MusicSource\?comment:!Copied /r" (i.e. show all files except comment "Copied")
 
//Count files in MusicSource folder
  $countsource = getinfo ("CountItems");
//If no random files left, option to reset comments and end script
  IF ($countsource == 0){
  IF (confirm ("No more random songs left in ""$MusicSource"",<crlf>Reset comments?")==1){
  goto "$MusicSource\?$MusicExtensions /r"; 
//Select all files
  sel a;
//Reset or remove comments
  comment;
  }

  ELSE{
  goto "$MusicSource\?$MusicExtensions /r";
  }
//Terminate script
  end (1);
  }

//Sort files randomly
  #331; 

//If random number > source files, select all files.  
  IF ($RandomNumber>$countsource){
  $RandomNumber=$countsource;
  }
//Select files from 1 to randomnumber
  sel 1, $RandomNumber;
//Comment selected files to "Copied"
  comment Copied;
//focus list
  focus;
//Using backupto instead of copyto to overcome similar file names such as Track-01, which will be suffixed to Track-01-01,Track-01-02 etc.
  backupto "$MusicDestination",,4;
  goto "$MusicDestination";
To see the attached files, you need to log into the forum.

arirish
Posts: 93
Joined: 13 May 2008 13:52

Re: Random Music Copier

Post by arirish »

Ah, this looks great! One thing I'm curious about - does it allow for more than one source folder?

My music is structured like this (example):

E:\Albums\Clash - London Calling\London Calling.ogg
E:\Songs\Clash Misc\Bank Robber.mp3
E:\Unsorted\Random Song.mp3

I'd like the script to 'find' the first two files, but overlook the 'unsorted' folder. Does the 'source' include subfolders? Ideally my source folder line would look like this:

//Music to copy from (don't add trailing \)
$MusicSource="E:\Albums;E:\Songs";

Thanks :)

EDIT: Never mind - I tried that out myself, and it does work, so this script it just what I wanted. Thanks so much :)

Post Reply