[Tutor] identifying if a path is heading into a zip file - windows

Dennis Lee Bieber wlfraed at ix.netcom.com
Sun Mar 20 15:21:41 EDT 2022


On Sun, 20 Mar 2022 02:13:52 +0000, Nathan Smith <nathan-tech at hotmail.com>
declaimed the following:

>path= 'c:\my folder\a file.zip\a folder in the zip'
>
	Just a comment... "\a" is a control character <BEL>. For literals,
easier to use / rather than \ -- Windows accepts either. If you really need
it, run os.path.normpath() on it.

>
>Is there a way for python to know, without me physically breaking it 
>down, that that path is in a zip file?
>

	Other than traversing the path components -- no. Especially if some
path components might be symbolic links and/or mount points

	Something like (untested -- may need work to handle the end-of-path
case):

import os.path

def embedded_file(aPath):
    ef = False
    while True:
        aPath = os.path.dirname(aPath)
        if aPath:
            if os.path.isfile(aPath):
                ef = True
                break
        else:
            break
    return ef


-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
	wlfraed at ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/



More information about the Tutor mailing list