[Tutor] How to copy file from a source, I do not know the source file name, Only path to the src directory I know

Joseph John jjk.saji at gmail.com
Tue Nov 9 13:15:56 CET 2010


Hi All
   I am trying our "Python" .
   My aim is to copy a file to a location and later removing the
file.I had written a small script which works.It works only if I
specify the source file name. I would like to make it work in a
scenario in which I do not know the name of the source file(the source
directory will have only one file at any time)

I am posting the script which I have done,How to modify the script to
copy the source file even if I do not know the name of the file
my script is below

###############################################
#!/usr/bin/python

# This script aims to copy file from one directoy to anothe and later
removing the files
# This script works when I know the source file name, I want to this
script to function even if I do not know the name of
# the file in "/home/joseph/Projects/Training/Python/example/One/"

import shutil
# "FromOne" is a file in /home/joseph/Projects/Training/Python/example/One/
src = "/home/joseph/Projects/Training/Python/example/One/FromOne"
#
dst2 = "/home/joseph/Projects/Training/Python/example/Two/"
dst3 = "/home/joseph/Projects/Training/Python/example/Three/"
#

#
#shutil.move(src, dst)
shutil.copy(src,dst2)
shutil.move(src,dst3)

######################################




-- 
Thanks
Joseph John
http://www.oss101.com/


More information about the Tutor mailing list