Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 anyone know how to use batch scripts?
Index -> General Programming
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Saad85




PostPosted: Thu Apr 12, 2007 11:09 pm   Post subject: anyone know how to use batch scripts?

i'm often cleaning and rearranging my music folder via batch scripts and programs, but as a result of that, sometimes folders get left with nothing but a picture (album art)

i needed a way to delete all these folders and i thought it would be a great way to learn more about cmd prompt and batch scripts. unfortunately, the syntax is less than user friendly and all the tutorials i've found assume you know everything about basic syntax.

i know i would use a for command with an if statement in it. i could check if the directory needs to be deleted via checking the size of the directory (if it's less than a few hundred kb then it obviously has no music in it) or, a better way would be to check if the folder doesn't have any .mp3 files in it. the only problem with this is that some of my songs aren't mp3's so it would need to be coupled with another if statement.

if anyone can help me with this, or point me to a site which can, i would be very grateful.

also, if cmd isn't a good way to do this sort of thing, please tell me.
Sponsor
Sponsor
Sponsor
sponsor
ericfourfour




PostPosted: Thu Apr 12, 2007 11:46 pm   Post subject: Re: anyone know how to use batch scripts?

I hardly know anything about batch scripts but I can tell you how to program this.

It will be much easier to do if you recursively go through all of your files.

The method would look like this:

- get all file/folder names in the current directory
- loop through every file
- if a file is not audio delete it
- if a file is a folder, call the method using that directory
- if the folder is empty, delete it

Pseudo code:
code:
void cleanMusicDir (string directory) {
    open directory stream
    load all file names onto the memory
    for each file name {
        if (file is not music) {
            delete file
        } else if (file is a directory) {
            cleanMusicDir (directory + file name)
            if (directory is empty) {
                delete directory // (the file)
            }
        }
    }
}
klopyrev




PostPosted: Fri Apr 13, 2007 6:46 am   Post subject: Re: anyone know how to use batch scripts?

Wow... Try putting all that pseudo code into Batch Script. I don't have the slightest idea of where to even begin. Easier said than done!
bugzpodder




PostPosted: Fri Apr 13, 2007 12:53 pm   Post subject: RE:anyone know how to use batch scripts?

i've worked with batch script and I dont know why. i suggest you use python script instead. they can be run via command line using a python interpreter
Saad85




PostPosted: Sat Apr 14, 2007 4:04 pm   Post subject: Re: RE:anyone know how to use batch scripts?

bugzpodder @ Fri Apr 13, 2007 1:53 pm wrote:
i've worked with batch script and I dont know why. i suggest you use python script instead. they can be run via command line using a python interpreter


hmm, i don't know how to use python, but this is good enough of a reason to learn.

and eric, i can't do that because it involves deleting all of my album covers. i only want to delete the ones that no longer have a song in that directory.
Display posts from previous:   
   Index -> General Programming
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: