This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Reverting an organize operation

Tags: None
(comma "," separated)
thrawn01
Registered Member
Posts
2
Karma
0

Reverting an organize operation

Fri May 08, 2009 4:21 pm
Like many of my friends, I ran the "Organise" operation in Amarok 2 without knowing what is does. I personally don't like organising my Mp3z in such a manner. So I created a python script to grab all the files out of the subdirectories and place them back into the my /Music directory. I figured someone else would find it useful.

NOTE: It doesn't delete the old directories, as I felt that might be dangerous operation. Its up 2 you to delete the empty directories.

PS: Amarok 2 has alot of potential, but 1.4 is the only player for me ATM.

Tags: amarok 2 organize organise python revert collection

#! /usr/bin/python

import os
import shutil


def scanDir( strPWD, strMoveTo ):
    # Scan all the files in this directory
    for strFile in os.listdir( strPWD ):
        # If the file is a dir
        if os.path.isdir( strFile ):
            # Scan this directory recursively
            scanDir( strPWD + "/" + strFile, strMoveTo )

        # If we are on the MoveTo level
        if( strPWD == strMoveTo ):
            continue

        strSrc = strPWD + "/" + strFile
        # If the file we are looking at is not a normal file
        if not os.path.isfile( strSrc ):
            continue

        # If the file doesn't already exist
        if os.path.exists( strMoveTo + "/" + strFile ):
            print strSrc, "Already exists in", strMoveTo
            continue
        print "move: ", strSrc,"  ",strMoveTo
        shutil.move( strSrc, strMoveTo )


if __name__ == "__main__":
    scanDir( os.getcwd(), os.getcwd() )


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Yahoo [Bot]