I've recently been developing a tool to track changes to a fairly large structured file system, and in the process got to thinking about how working with path names could be improved. The problems I've had with using just os and os.path have lead to three objectives of any new implementation:<div>

<br><div><div><div>1.  Cleaner handling of paths names, specifically constructing path names without the need for a lot of nested os.path.join() and os.split() functions.</div><div>2.  Allow a validation of paths names based on predefined rules. (Although this requirement might be very specific to my use case)</div>

<div>3.  Allow caching of file attribute data so that queries do not have to wait the disk or network to respond (although at the cost of accuracy).</div><div><br></div><div>The first can be met with behaviour as follows, basically handling paths as containers of sub-paths:</div>

<div><br></div><div><div><div>>>> root = Path('/usr')</div><div>>>> print([n for n in root])</div><div>['bin', 'local', 'lib', 'share']</div><div>>>> print([n for n in root.dirs])</div>

<div>['bin', 'local', 'lib', 'share']</div><div>>>> print([n for n in root.files])</div><div>[]</div><div>>>> root['local/share']</div><div>Path('/usr/local/share')</div>

<div>>>> root['/usr/local/share']</div><div><div>Path('/usr/local/share')</div></div><div>>>> share = Path('/usr/local/share')</div></div><div>>>> share in root</div><div>

True</div><div><br></div><div>The second can be met by allowing Path to be subclassed and defining factory functions for the creation of sub-paths:</div><div><br></div><div>>>> root = Path('/usr')</div><div>

>>> root.factory = my_factory_function</div><div>>>> root['local/share']</div><div>MyPath('/usr/local/share')</div><div><br></div><div>The third can be met be allowing all disk calls to be asynchonous:</div>

<div><br></div><div>>>> path = Path('/home/david/newfile', async=True)</div><div>>>> path.touch()</div><div>>>> path.exists()</div><div>False</div><div>>>> time.sleep(2)</div></div>

</div></div><div>>>> path.exists()</div><div>True</div><div><br></div><div>This could all be implemented in pure python using os and os.path, and threading for asynchonous calls. I haven't yet thought through a complete specification for Path, but I image it would need to contain functions such as exists(), isfile(), isdir(), stat(), walk(), and allow iterator access to children.</div>

<div><br></div><div>Does anyone else see a usefulness for this?</div><div><br></div><div>Regards</div><div>David</div><div><br></div></div>