Help please with code to find and move files.
- From: inFocus@xxxxxx
- Date: Sun, 30 Dec 2007 21:04:23 -0500
Hello,
I am new to python and wanted to write something for myself where
after inputing two words it would search entire drive and when finding
both names in files name would either copy or move thoe files to a
specified directory.
But couple of attempts did not work as desired this is one of them.
Could someone help fix it or maybe give a better example.
Thank you very much.
import os, os.path, shutil
path = r"c:\\"
dest_file = 'C:\\files'
name_search = raw_input('Please enter name searchs : ').split()
dup = []
for root, dirs, files in os.walk(path):
for name in files:
file_name = os.path.join(root, name)
if (name_search[0] in file_name) and (name_search[1]
in file_name):
#if os.path.join(root, name) in dest_file:
if file_name in dup:
break
else:
print "copied %s to %s" % (name,
dest_file)
shutil.copy(os.path.join(root, name),
dest_file)
dup.append(file_name)
.
- Follow-Ups:
- Re: Help please with code to find and move files.
- From: John Machin
- Re: Help please with code to find and move files.
- From: infixum
- Re: Help please with code to find and move files.
- Prev by Date: evolution-python
- Next by Date: Re: Help please with code to find and move files.
- Previous by thread: evolution-python
- Next by thread: Re: Help please with code to find and move files.
- Index(es):