-
-
Notifications
You must be signed in to change notification settings - Fork 187
Closed
Description
Hi,
The issue I have is that I get the errormessage : "fs.errors.CreateFailed: root path 'C:\pyfilesytem_test_dir\DJI_0355.JPG' does not exist" when using getinfo. I have tried several ways to specify the path, but still get the issue.
I provide samle code below.
Sample 1
import fs
class WindowsFileHandler:
def __init__(self, file_path):
self.file_path = file_path
def extract_filename_and_path(self):
with fs.open_fs('osfs://' + self.file_path) as filesystem:
if filesystem.exists(self.file_path):
# Extract the filename and path
file_info = filesystem.getinfo(self.file_path)
filename = file_info.name
directory = file_info.parent
return filename, directory
else:
return None, None
if __name__ == '__main__':
# Replace 'C:/path/to/your/file' with the actual path to the file on your Windows system.
file_path = r'C:\pyfilesytem_test_dir\DJI_0355.JPG'
file_handler = WindowsFileHandler(file_path)
filename, directory = file_handler.extract_filename_and_path()
if filename and directory:
print("File Name:", filename)
print("Directory Path:", directory)
else:
print("File not found.")
Sample 2
`import fs
from fs import open_fs
path = 'C:\\test_dir\\DJI_0355.JPG' # Use double backslashes or raw string for Windows path
with open_fs(path) as filesystem:
if filesystem.exists(path):
# Extract the filename and path
filename = filesystem.getinfo(path).name
directory = filesystem.getinfo(path).parent
print("File Name:", filename)
print("Directory Path:", directory)
else:
print("File not found.")
Both codesnippets gets the following result:
"fs.errors.CreateFailed: root path 'C:\pyfilesytem_test_dir\DJI_0355.JPG' does not exist"
Event though the path and file exists.
Thanks in advance for support or suggestions!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels