'C:/Python25/python.exe'we want to separate a file name 'python.exe' from the path to it 'C:/Python25/'. With the help of a standard Python module os.path it is an easy task to do:
mypath = 'C:/Python25/python.exe'
separated = os.path.split(mypath)
where 'separated' is a tuple with two items. First is the path, second is the filename.
Do you also want to separate file name from its extension (e.g. '.exe' in our case)? It's easy:
name,extension = os.path.splitext(separated)
Do you also want to reverse this process? Just call the os.path.join() function:
completefilename = os.path.join(separated,separated)
Finally, I also wanted to compress some files to save disk space. There is a standard Python library called zipfile which supports creating .zip files (it also requires another library called zlib for compression of the .zip archives). Usage is simple:
f = zipfile.ZipFile( 'myfile.zip', 'w', compression = zipfile.ZIP_DEFLATED)
The 'ZIP_DEFLATED' option tells the ZipFile class to compress the data, otherwise no compression is done.