473,241 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,241 software developers and data experts.

shutil module (directory input from terminal)

hello folks

i am trying to tweak the current codes so that later when i call it from the terminal i can provide sourcefile and the destination file rather being fixed in the code. because now i have to specify the sourcefile and the destinationfile in codes and not left to be specified from the terminal. i want to be able to do this.

python shutil_copy.py sourcefile, destinationfile

Expand|Select|Wrap|Line Numbers
  1. import shutil 
  2. shutil.copyfile(srcfile, dstfile) # copy data only
Jan 27 '09 #1
4 2581
2,851 Expert Mod 2GB
The arguments passed to the script on the command line are available in list object sys.argv. Example at command prompt:
Expand|Select|Wrap|Line Numbers
  1. python arg.py argument1
Expand|Select|Wrap|Line Numbers
  1. # arg.py
  2. import sys
  4. print sys.argv
  5. print sys.argv[1]
Expand|Select|Wrap|Line Numbers
  1. ['arg.py', 'argument1']
  2. argument1
Jan 27 '09 #2

hey man, thanks for replay

i did the following

Expand|Select|Wrap|Line Numbers
  1. #arg.py
  2. import sys
  3. import shutil
  4. shutil.copytree(sys.argv[0], sys.argv[1] )
and i got the following error, for the record i am trying to copy files from one directory to another one

waseem@Linux:~/Project2$ python copying_photos.py '/home/waseem/My Pictures/yemen 2008/2008/1' '/home/waseem/h'
Traceback (most recent call last):
File "copying_photos.py", line 4, in <module>
shutil.copytree(sys.argv[0], sys.argv[1] )
File "/usr/lib/python2.5/shutil.py", line 109, in copytree
names = os.listdir(src)
OSError: [Errno 20] Not a directory: 'copying_photos.py'
Jan 28 '09 #3
What u should do is modify the line
Expand|Select|Wrap|Line Numbers
  1. shutil.copytree(sys.argv[0], sys.argv[1] )
Expand|Select|Wrap|Line Numbers
  1. shutil.copytree(sys.argv[1], sys.argv[2] )
Make sure that the source is a directory, an existing one and the destination is a non-existent directory name.
Jan 28 '09 #4
Thank you very much.

it worked perfectly
Jan 28 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

by: bmgz | last post by:
I am have made a simple script that moves all desktop clutter (ie files that are not *.lnk) to a specified folder eg. c:\myhome\mydocs\desktopdebris\2003-12-16 ...
by: Peter Åstrand | last post by:
There's a new PEP available: PEP 324: popen5 - New POSIX process module A copy is included below. Comments are appreciated. ---- PEP: 324 Title: popen5 - New POSIX process module
by: Daniel Bickett | last post by:
Hello, I'm writing an application in my pastime that moves files around to achieve various ends -- the specifics aren't particularly important. The shutil module was chosen as the means simply...
by: Antoine De Groote | last post by:
Google tells quite some things about it, but none of them are satisfactory. I'm on Windows, and shutil operations (e.g. move, copy) throw Permission denied all the time, for the source files. It...
by: David Nicolson | last post by:
Hi, I wasn't exactly sure where to send this, I don't know if it is a bug in Python or not. This is rare, but it has occurred a few times and seems to be reproducible for those who experience...
by: Ben Sizer | last post by:
I need to copy directories from one place to another, but it needs to overwrite individual files and directories rather than just exiting if a destination file already exists. Previous suggestions...
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
by: yinglcs | last post by:
Hi, Is there a c library which does shutil.copy2() in python? Basically copy a file from 1 directory to another? import shutil import os shutil.copy2(r"C:\test\test",r"C:\test1\test")
by: David C. Ullrich | last post by:
Running OS X 10.4 "Tiger". Various references by Apple and others say that there exists a module that gives Quartz bindings, allowing all sort of graphics things in Python. Sure enough, after...
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.