•
•
•
•
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
![]() |
•
•
Join Date: Oct 2006
Posts: 24
Reputation:
Rep Power: 2
Solved Threads: 0
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.
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.
python Syntax (Toggle Plain Text)
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' % (sys.argv[1], 'copy' + sys.argv[1])) elif sys.platform[:5] == 'linux': 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. **
** 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. **
•
•
Join Date: Oct 2006
Posts: 24
Reputation:
Rep Power: 2
Solved Threads: 0
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 :
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
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:
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. **
** 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. **
•
•
Join Date: Oct 2006
Posts: 24
Reputation:
Rep Power: 2
Solved Threads: 0
Thanks Again.... It works without error.. but the file cannot copy. I am on linux system, It works without error
here is the code :
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]))
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. **
** 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. **
![]() |
•
•
•
•
•
•
•
•
DaniWeb Python Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
access activation api blogger blogging blogs code code injection combo dani daniweb data debugging development dreamweaver dropdownlist epilepsy foundation gdata google gpl griefers hackers html innovation javascript key linux microsoft module net newbie news openbsd presentation product programming reuse rss serial source tags vista web windows wpf wysiwyg xml
- Newbie needs help! SOS! (PHP)
- Javascript newbie help! (JavaScript / DHTML / AJAX)
- Need simple code for VB.NET (VB.NET)
- help me please.. (simple quiz) (Visual Basic 4 / 5 / 6)
- CAn anyone provide me a very simple code for shopping cart? (PHP)
- Creating simple array... headache. (Java)
- Code examples for events (e.g. buttons) for a newbie (Visual Basic 4 / 5 / 6)
- Newbie who is lost. (C++)
- I am a girl doing my 1st simple program (C)
Other Threads in the Python Forum
- Previous Thread: newbie: concatenating multiple RegEx's
- Next Thread: pygame time


Linear Mode