We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hi, Thanks for the good library.
Can we check path existence asynchronously with this library? I mean something like this:
path_existence = await aiofiles.path.exists(some_path)
If not, I request this feature. Thanks again.
The text was updated successfully, but these errors were encountered:
I noticed that the implementation for exists is actually a call to os.stat and making sure it's not raising an exception.
exists
os.stat
def exists(self): """ Whether this path exists. """ try: self.stat() except OSError as e: if not _ignore_error(e): raise return False except ValueError: # Non-encodable path return False return True
As os.stat is wrapped in aiofiles.os.stat, I think it would be rather straightforward to achieve that.
aiofiles.os.stat
Sorry, something went wrong.
For anyone else coming to this, I'm using the following baed on @dangillet's observation above.
from pathlib import Path, _ignore_error as pathlib_ignore_error from typing import Union import aiofiles.os async def path_exists(path: Union[Path, str]) -> bool: try: await aiofiles.os.stat(str(path)) except OSError as e: if not pathlib_ignore_error(e): raise return False except ValueError: # Non-encodable path return False return True
Successfully merging a pull request may close this issue.
Hi,
Thanks for the good library.
Can we check path existence asynchronously with this library? I mean something like this:
If not, I request this feature. Thanks again.
The text was updated successfully, but these errors were encountered: