Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

simple file copy program

Name: Anonymous 2010-01-18 23:35

need a bash script or python to copy files in batches of 500 and put them into subdirectories

there can be any number of files (I have 15k), and the filenames are irrelevant, and the names of the subdirectories that are created to house the files is irrelevant

here's what I was trying to get work in python but it
errors out at file 339, don't know why



def BreakUp(indir):
   
    biglist = glob.glob('*.mp3')
    dircount = 0
    filecount = 0

    while biglist:
        dircount += 1
        os.mkdir('subdir'+str(dircount))
        for i in range(500):   
            filecount += 1
            try:
                src = biglist[filecount].translate("(copy)")
                os.system ("mv"+ " " + src + " subdir"+ str(dircount))          
                biglist.remove(src) 
            except IndexError:
                raise IndexError, "could not return item " + str(filecount) + " from list " + str(biglist)
        continue
               
           
       

if __name__ == '__main__':
    BreakUp(".")

Name: Anonymous 2010-01-19 2:59

>>3
I'm learning about perl and regular expressions.  I'm going to try and understand what the line does.  It would be appreciated if you could provide feedback on it.

perl -e gets whatever the stream is and compiles it without needing to save the script.
mkdir$_ creates a new directory, the name of it is the special variable
for 0..(@f=<*.mp3>)/500; This line I have some difficulty understanding.
rename$_ tells mkdir$_ that the directory will be what's following.
,int($n++/500) is what $_ becomes.  It counts how many groups of 500 have been so far and makes it that.
."/$_"for@f' renames the file in the current n position in @f to have the directory location included in the name, EG ./516.mp3 will become ./1/516.mp3 and ./142.mp3 will become ./0/142.mp3 .

Willing to help?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List