[Tutor] if file == exists, then dont copy it

Tor Stormwall tor@agent.creson.com
Sat, 24 Nov 2001 11:41:55 +0100 (CET)


Hi!

I'm trying to write a section in a piece of code that
if a file exists with a given name it will copy the file
to that name. For example, file1 to my_new_file

I've got the name config_file_named defined as TEST3, like this:
config_file_name = "TEST3"

I've imported exists from os.path.
The code should  act something like:
if file: then do not copy, else copy the file.


The code looks like this:
    from os.path import exists
    verbose=1 # is it here?
    force=0   # are whe gonna force? noo
    if exists(config_file_name) and not force:
        if verbose: print file, ' is already created'
        else:
            print "copying file"
            os.system('cp MYFILE ' + config_file_name)



The program seem to skip everything after force=0 and
then exit.



Best Regards,
Tor Stormwall

* - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
|   M A Y   T H E   S O U R C E   B E   W I T H   Y O U   |
|						          |
| Tor Stormwall			mailto:tor@stormwall.org  |
| http://www.creson.com/~tor  				  |
| 						   	  |
| http://www.sslug.dk		http://www.stormwall.org  |
| http://www.FreeBSD.org	http://www.muf.se         |
|							  |
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - *