[Python] Sample Ordner löschen

Dieses Thema im Forum "Projekte / Codes" wurde erstellt von cable, 18. Februar 2010 .

  1. 18. Februar 2010
    Sample Ordner löschen

    Hey!

    Hatte das Problem, dass ich ~150 Ordner hatte, in denen sich noch ein Sample Ordner + Inhalt befand. Hatte natürlich keine Lust das alles per Hand zu löschen und hab mir in 4 Minuten dann dieses Script geschrieben, welches das automatisch löst. Will euch den Code nicht vorenthalten!
    Dieses Script läuft auf Unix und Windows Systemen!

    Python Version: 3.1
    PHP:
    import os

    folder 
    input ( 'Folder path: ' )
    folder  folder [ 0 :- 1 ]    

    def delFiles ( path ):
        for 
    file in os . listdir ( path ):
            if 
    os . path . isfile ( os . path . join ( path file )):
                try:
                    
    os . remove ( os . path . join ( path file ))
                
    except :
                    print(
    'Could not delete' file 'in' path )
        

    def delSample ( path ):
        for 
    dir in os . listdir ( path ):
            if 
    os . path . isdir ( os . path . join ( path dir )):
                if 
    dir  ==  'Sample'  or  dir  ==  'sample' :
                    
    delFiles ( os . path . join ( path dir ))
                    try:
                        
    os . rmdir ( os . path . join ( path dir ))
                        print(
    'Sample deleted!' )
                    
    except :
                        print(
    'Could not remove' path )
                else:
                    
    delSample ( os . path . join ( path dir ))
        
    delSample ( folder )
    print(
    'Finished!' )
    Python Version: 2.6
    PHP:
    import os

    folder 
    raw_input ( 'Folder path: ' )
    folder  folder [ 0 :- 1 ]    

    def delFiles ( path ):
        for 
    file in os . listdir ( path ):
            if 
    os . path . isfile ( os . path . join ( path file )):
                try:
                    
    os . remove ( os . path . join ( path file ))
                
    except :
                    print 
    'Could not delete' file 'in' path
        

    def delSample
    ( path ):
        for 
    dir in os . listdir ( path ):
            if 
    os . path . isdir ( os . path . join ( path dir )):
                if 
    dir  ==  'Sample'  or  dir  ==  'sample' :
                    
    delFiles ( os . path . join ( path dir ))
                    try:
                        
    os . rmdir ( os . path . join ( path dir ))
                        print 
    'Sample deleted!'
                    
    except :
                        print 
    'Could not remove' path
                
    else:
                    
    delSample ( os . path . join ( path dir ))
        
    delSample ( folder )
    print 
    'Finished!'
    Der Pfad sollte so angegeben werden:
    Code:
    C:\Movies\
    greez
     
  2. 19. Februar 2010
    AW: Sample Ordner löschen

    coole idee

    hat 1a geklappt


    bw haste herr kollege
     
  3. 7. April 2010
    AW: Sample Ordner löschen

    Man kann auch einfach in den übergeordneten Ordner, der 150 Ordner gehen und via. Windows-Suche nach "Sample" suchen -> STRG + A -> DEL -> RETURN -> Done.

    Das toppt deine 4 Minuten noch
     
  4. Video Script

    Videos zum Themenbereich

    * gefundene Videos auf YouTube, anhand der Überschrift.