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

Joel Goldstick joel.goldstick at gmail.com
Tue Nov 9 13:43:35 CET 2010


On Tue, Nov 9, 2010 at 7:15 AM, Joseph John <jjk.saji at 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)
>
> 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/


os.listdir(*path*)¶ <http://docs.python.org/library/os.html#os.listdir>

Return a list containing the names of the entries in the directory given by
*path*. The list is in arbitrary order. It does not include the special
entries '.' and '..' even if they are present in the directory.




>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Joel Goldstick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101109/fecd7e0d/attachment-0001.html>


More information about the Tutor mailing list