glob - Impossible to delete files in a loop with python -


i want delete files on folder , have error.

my code

for f in glob ('sub/*.sub'):      subprocess.call(["php", "aes.class.php" , f])      shutil.rmtree(f)      #deplacement des fichier      d in glob ('*.ass'):           shutil.move(d, 'sync') 

it gives me following error:

traceback (most recent call last):   file "start.py", line 26, in <module>     shutil.rmtree(f)   file "/usr/lib64/python2.7/shutil.py", line 239, in rmtree     onerror(os.listdir, path, sys.exc_info())   file "/usr/lib64/python2.7/shutil.py", line 237, in rmtree     names = os.listdir(path) oserror: [errno 20] not directory: 'sub/ep01.sub' 

how delete files extension .sub in folder?

you want os.remove rather shutil.rmtree. specifically, former method removing file whereas latter designed remove directory (along of it's contents).

for f in glob ('sub/*.sub'):      subprocess.call(["php", "aes.class.php" , f])      os.remove(f)      #deplacement des fichier      d in glob ('*.ass'):           shutil.move(d, 'sync') 

Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -