Note that there are some explanatory texts on larger screens.

plurals
  1. POMatching file paths regardless of network protocol
    primarykey
    data
    text
    <p>I am developing a tool that deletes files on network paths based on several conditions. I would like to exclude certain paths from being checked and am having trouble finding a suitable method.</p> <p>Some of the paths the program handles are as follows:</p> <pre><code>nfs_path = "nfs://Sharepoint/Path/to/Folder/File.ext" smb_path = "smb://SERVER/Sharepoint/Path/to/Folder/File.ext" afp_path = "afp://server/Sharepoint/Path/to/Folder/File.ext" upnp_path = "upnp://277b787b-5b27-b46f-1687-91100ada8d1f/Path/to/Folder/File.ext" exclusion = "smb://user:pass@server/E/Downloads/Path/to/Folder" </code></pre> <p>As you can see some of the paths use credentials, while others do not. These network paths should be able to be matched to one another.</p> <p>In short, I would like to get confirmation that <code>File.ext</code>, using any protocol, is part of <code>Folder</code> (which I excluded from checking). Since I'm not an expert with path manipulation or regular expressions, I'm in a bind. I attempted the regex below, which fails for the NFS path since it takes the share name (<code>E</code>) too. It completely fails for the UPnP paths, because of their totally different nature.</p> <pre><code>"(?P&lt;protocol&gt;((smb|nfs|afp|upnp)://((.+:.+@)?.+?/)?))?(?P&lt;directory&gt;.+)" </code></pre> <p>I also tried using the <code>os.path</code> module, but the methods seem not suitable. </p> <p>While waiting for an answer that is more efficient, I built a correctly parsing regex that will only capture the folder structure and ignore the prefix:</p> <pre><code>"(?:smb|afp|nfs|upnp)://(?:(?:.+):(?:.+)@)?(?:.+?)/(?P&lt;tail&gt;.*)$" </code></pre> <p>Could anyone point me in the direction of a more efficient approach? I think this will be too memory consuming to test for a lot of different files.</p> <p>It needs to work on python 2.6 or lower, since it is an addon to an existing program.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload