import os import shutil from os import path from shutil import make_archive from zipfile import ZipFile if __name__ == "__main__": main() def main(): if path.exists("textfile.txt"): src = path.realpath("textfile.txt") print src head, tail = path.split( src ) print "path:" + head print "file:" + tail dst = src + ".bak" shutil.copy( src, dst) shutil.copystat( src, dst ) os.rename( "textfile.txt.bak", "newfile.txt" ) root_dir, tail = path.split( src ) shutil.make_archive( "archive", "zip", root_dir ) with ZipFile( "testzip", "w" ) as newzip: newzip.write( "newfile.txt" ) newzip.write( "textfile.txt" )
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question