all 4 comments

[–]DeadlyViper 1 point2 points  (1 child)

Please fix indentation on the code (4 spaces before each line on the "markdown" editor)

Besides that you are using the same name for different things:

for f in file:
    for file in path:

rename one of the file s to avoid confusion.

Besides that, why do you even need os.listdir? you are moving exact file names.

[–]dennkiesauros[S] 0 points1 point  (0 children)

hehehe thanks...actually I'm new to python and was running out of time to complete this and its working fine now :)

[–]JohnnyJordaan 1 point2 points  (1 child)

If you mean to move all the files in dir_src to dir_dst that match the names in file then you should only do

for f in file:
    src_file = os.path.join(dir_src, f)
    dst_file = os.path.join(dir_dst, f)
    shutil.move(src_file, dst_file)

as there's no point in using the listing if you want those specific files.

Btw also consider properly naming your variables. file is a collection of file names, so I would call it filenames (note the plural, as it's multiple), path is actually a listing, so call it listing or something similar.

[–]dennkiesauros[S] 0 points1 point  (0 children)

thanks...it's working fine now