Thanks I was able to solve it by " dirList=os.listdir(src) for fname in dirList: print fname ffname = '/home/joseph/Projects/Training/Python/example/One/'+fname print ffname #shutil.copy(ffname,dst2) shutil.move(ffname,dst3) "
On Tue, Nov 9, 2010 at 4:38 PM, Evert Rol <evert....@gmail.com> wrote: >> 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) > > Have a look at the os module, specifically os.listdir() > The glob module could also be handy. > > Cheers, > > Evert > >> >> 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/ >> _______________________________________________ >> Tutor maillist - tu...@python.org >> To unsubscribe or change subscription options: >> http://mail.python.org/mailman/listinfo/tutor > > -- Thanks Joseph John http://www.oss101.com/ _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor