Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How would you write a script (preferably for the Windows commandline) that:

  • Examines thousands of MP3 files stored on a single drive (e.g., G:\)
  • Randomizes the collection
  • Populates a series of directories up to 650MB worth of songs (without exceeding 650MB)
  • Every song is shucked exactly once
  • (Optional) The directory size comes as close as possible to 650MB

The DIR, COPY, and XCOPY commands have no explicit file size switches.

A few Google searches have come up with:

It would be ideal if UNIX-like environments can be avoided.

My question, then: How do you compare file (or directory) sizes using the Windows commandline?

share|improve this question

migrated from stackoverflow.com Feb 9 '10 at 21:54

This question came from our site for professional and enthusiast programmers.

4  
Why do you need it to leverage DOS? –  Irwin M. Fletcher Feb 9 '10 at 17:45
    
Windows XP Pro is the environment. DOS is not necessary if there is a Windows tool that can do the same task. Also, would this be a better question for serverfault? –  Dave Jarvis Feb 9 '10 at 18:02
2  
WinXP Pro does not even have DOS on it –  Joe Philllips Feb 9 '10 at 18:33
1  
I guess by saying DOS Dave means Windows command interpreter (cmd). –  Helen Feb 9 '10 at 18:46
1  
I know what he meant but I figured I'd bring that up anyway since this is a learning site and there should be correct information here –  Joe Philllips Feb 9 '10 at 20:23
show 3 more comments

3 Answers

You could use JavaScript WSH script. See FileSystemObject.

var WShell = WScript.CreateObject("WScript.Shell");
var fso = WScript.CreateObject("Scripting.FileSystemObject");

VB is evil.

share|improve this answer
    
How could this be integrated into a working shell script? –  Dave Jarvis Feb 9 '10 at 18:29
    
You can use GetFolder and GetFile to iterate through folders and get the file information. The GetFolder page has a great example, and the File object returned by GetFile has a size attribute. after you selected your files you can use the fso.CopyFile method to copy the selected files. –  Fozi Feb 9 '10 at 19:29
add comment

What is your definition of a "unix-like environment"? Does a language like Tcl or Python fall into that category? Such programming languages are perfect for tasks like this, with built-in features for scanning directories, getting file sizes, moving files, etc.

Don't hamstring yourself by using a limited language like the windows batch language. Pick a real programming language that has a native port to windows and you're job will likely be much easier.

share|improve this answer
    
Was just looking to create a simple script. I could do it in bash in about 30 minutes. The problem is I want to hand off the program to a friend (a one-time project). Python is a great idea. –  Dave Jarvis Feb 9 '10 at 18:49
add comment
up vote 0 down vote accepted

iTunes has such a feature.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.