A. Joseph wrote:
os.walk traverses the directory tree, so I'm not sure why you think that
your program needs to use recursion? wouldn't a plain loop work?
import os, shutil
for dirpath, dirnames, filenames in os.walk(directo ry):
for name in filenames:
source = os.path.join(di rpath, name)
... check extension and determine target directory ...
destination = os.path.join(ta rgetdir, name)
shutil.move(sou rce, destination)
tweak as necessary.
</F>
I want to search through a directory and re-arrange all the files into e.g
>
All .doc files go into MS WORD folder, all .pdf files goes into PDF Folder.
>
I`m thinking of doing something with the os.walk(path) method from os
module, I need some ideal how the algorithm should look like, maybe
recursive ..any deal?
>
All .doc files go into MS WORD folder, all .pdf files goes into PDF Folder.
>
I`m thinking of doing something with the os.walk(path) method from os
module, I need some ideal how the algorithm should look like, maybe
recursive ..any deal?
your program needs to use recursion? wouldn't a plain loop work?
import os, shutil
for dirpath, dirnames, filenames in os.walk(directo ry):
for name in filenames:
source = os.path.join(di rpath, name)
... check extension and determine target directory ...
destination = os.path.join(ta rgetdir, name)
shutil.move(sou rce, destination)
tweak as necessary.
</F>