[Tutor] identifying if a path is heading into a zip file - windows
dn
PythonList at DancesWithMice.info
Sun Mar 20 13:47:32 EDT 2022
On 20/03/2022 22.02, Alan Gauld via Tutor wrote:
>> Take a second path:
>>
>> path= 'c:\my folder\a file.zip\a folder in the zip'
>>
>> Is there a way for python to know, without me physically breaking it down, that that path is in a zip file?
>>
> I don’t think so, the standard library tools simply analyse the text.
> You would need to write a function that traversed the path checking for isfile()
Can't say I've ever tried this. (nor do I use MS-Windows)
You rightly suggest that file.zip\archive_folder might involve a
zipped-archive, but that zipped.tie\single_use would (possibly?probably)
not.
There may be a reliance on 'good practice'. IIRC, just because a file
has the 'extension' ".zip" is an indication of its purpose; but not a
definition or restriction. Thus "long.zip" may not be an archive, but
"monday.backup" is. YMMV!
<end of pouring cold water on your ideas>
Referring to the second-half of the question: (and it may vary according
to OpSys in-use!) can we assume that the back-slash (\) is a character
that may *not* be used within a file-name? - is only used within paths
to separate folder- and file-names?
Putting it all together, find()-ing the following sub-strings in "path":
- "zip" would not be adequate, eg "zipped"
- ".zip" similarly, eg "tie.zip.button"
- might ".zip\" do the trick?
--
Regards,
=dn
More information about the Tutor
mailing list