User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 425,909 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,835 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser: Programming Forums
Views: 232 | Replies: 7
Reply
Join Date: Oct 2006
Posts: 24
Reputation: bimaljr is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
bimaljr bimaljr is offline Offline
Newbie Poster

Help newbie : need simple code

  #1  
Jul 25th, 2008
Hello
I am fresh newbie in Python world. I need a python code that just copy my input file with a different name. I just want to test it.

Example.
A simple scipt file : copyfile.py
when I do a command like "python copyfile.py 1.jpg" it would copy the "1.jpg" with a different name "copy1.jpg" .
I just want to copy file with "copy" name before every file I input.

I just want to test it with my PHP code. Thanks.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2008
Location: Durham, NC
Posts: 203
Reputation: jlm699 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 29
jlm699's Avatar
jlm699 jlm699 is offline Offline
Posting Whiz in Training

Re: Help newbie : need simple code

  #2  
Jul 25th, 2008
  1. import sys, os
  2.  
  3. if len(sys.argv) != 2:
  4. print 'Usage: python copy.py <file_to_copy>'
  5. sys.exit(0)
  6.  
  7. if sys.platform[:3] == 'win':
  8. os.system('copy %s %s' % (sys.argv[1], 'copy' + sys.argv[1]))
  9. elif sys.platform[:5] == 'linux':
  10. os.system('cp %s %s' % (sys.argv[1], 'copy' + sys.argv[1]))
Last edited by jlm699 : Jul 25th, 2008 at 10:17 am.
Let's Go Pens!

** Just because I reply to your question does not invite you to PM me. Keep discussions on the thread of topic, I will not answer your questions over PM. **
Reply With Quote  
Join Date: Oct 2006
Posts: 24
Reputation: bimaljr is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
bimaljr bimaljr is offline Offline
Newbie Poster

Re: Help newbie : need simple code

  #3  
Jul 25th, 2008
Thanks for reply. I don't know the how to notify this script the input file.. mean I don't know the replacement for <file_to_copy> , that's why I confused.

Please provide what to replace with <file_to_copy>

I got this error :
File "script.py", line 3
print 'Usage: python copy.py <file_to_copy>'
^
IndentationError: expected an indented block
Reply With Quote  
Join Date: Jul 2008
Location: Durham, NC
Posts: 203
Reputation: jlm699 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 29
jlm699's Avatar
jlm699 jlm699 is offline Offline
Posting Whiz in Training

Re: Help newbie : need simple code

  #4  
Jul 25th, 2008
You're getting an Indentation error. I didn't type that out in an editor so the indentation will be off. Go through and re-tab all the lines that should be tabbed.

An example usage:
python copy.py my_favorite_image.jpg
Let's Go Pens!

** Just because I reply to your question does not invite you to PM me. Keep discussions on the thread of topic, I will not answer your questions over PM. **
Reply With Quote  
Join Date: Oct 2006
Posts: 24
Reputation: bimaljr is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
bimaljr bimaljr is offline Offline
Newbie Poster

Re: Help newbie : need simple code

  #5  
Jul 25th, 2008
Thanks Again.... It works without error.. but the file cannot copy. I am on linux system, It works without error
here is the code :
import sys, os
if len(sys.argv) != 2:
print 'Usage: python copy.py <file_to_copy>'
sys.exit(0)
if sys.platform[:3] == 'win':
os.system('copy %s %s' % (argv[1], 'copy' + argv[1]))
elif sys.platform[:5] == 'linux':
os.system('cp ' % (argv[1], 'copy' + argv[1]))
Reply With Quote  
Join Date: Oct 2006
Posts: 24
Reputation: bimaljr is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
bimaljr bimaljr is offline Offline
Newbie Poster

Re: Help newbie : need simple code

  #6  
Jul 25th, 2008
Sorry now it works perfectly.. I done a mistake.. used tab on 4,8 and 10 line. Used space. and problem solved. Thanks once again.
Reply With Quote  
Join Date: Jul 2008
Location: Durham, NC
Posts: 203
Reputation: jlm699 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 29
jlm699's Avatar
jlm699 jlm699 is offline Offline
Posting Whiz in Training

Re: Help newbie : need simple code

  #7  
Jul 25th, 2008
I don't know how that is not giving you any errors. There is no indentation and you're missing the %s %s after the cp command on the last line.
Let's Go Pens!

** Just because I reply to your question does not invite you to PM me. Keep discussions on the thread of topic, I will not answer your questions over PM. **
Reply With Quote  
Join Date: Oct 2006
Posts: 24
Reputation: bimaljr is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
bimaljr bimaljr is offline Offline
Newbie Poster

Re: Help newbie : need simple code

  #8  
Jul 25th, 2008
Thanks a lot... It is working prefectly.. Thank you
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Python Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Python Forum

All times are GMT -4. The time now is 7:56 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC