in the last examplei pointed out that glob returns names with directory pathswhereas listdir gives raw base filenames for convenient processingscripts often need to split glob results into base files or expand listdir results into full paths such translations are easy if we let the os path module do all the work for us for examplea script that intends to copy all files elsewhere will typically need to first split off the base filenames from glob results so that it can add different directory names on the frontdirname ' :\temp\partsimport glob for file in glob glob(dirname '/*')headtail os path split(fileprint(headtail'=>'(' :\\other\\tail) :\temp\parts part = :\other\part :\temp\parts part = :\other\part :\temp\parts part = :\other\part :\temp\parts part = :\other\part herethe names after the =represent names that files might be moved to converselya script that means to process all files in different directory than the one it runs in will probably need to prepend listdir results with the target directory name before passing filenames on to other toolsimport os for file in os listdir(dirname)print(dirnamefile'=>'os path join(dirnamefile) :\temp\parts part = :\temp\parts\part :\temp\parts part = :\temp\parts\part :\temp\parts part = :\temp\parts\part :\temp\parts part = :\temp\parts\part when you begin writing realistic directory processing tools of the sort we'll develop in you'll find these calls to be almost habit walking directory trees you may have noticed that almost all of the techniques in this section so far return the names of files in only single directory (globbing with more involved patterns is the only exceptionthat' fine for many tasksbut what if you want to apply an operation to every file in every directory and subdirectory in an entire directory treefor instancesuppose again that we need to find every occurrence of global name in our python scripts this timethoughour scripts are arranged into module packagea directory with nested subdirectorieswhich may have subdirectories of their own we could rerun our hypothetical single-directory searcher manually in every directory in the treebut that' tediouserror proneand just plain not fun file and directory tools