Showing posts with label path. Show all posts
Showing posts with label path. Show all posts

2/26/2023

split filename and dir using os.path.split

 refer to code


.

import os

path = '/Users/source_code/final_data/test/X51006647933.jpg'

# Split the path into directory name and file name
dirname, filename = os.path.split(path)

# Print the file name
print(filename) # Output: X51006647933.jpg

..


Thank you.

πŸ™‡πŸ»‍♂️

www.marearts.com

12/13/2022

search all certain files recursively including subfolder - python example

 

refer to code

..

from pathlib import Path
mypath = "folder1/folder2"
for path in Path(annotation_addr).rglob('*.json'):
print(path) #full path
print(path.name) #file name

..


Thank you.

www.marearts.com

πŸ™‡πŸ»‍♂️

5/14/2022

pathlib, path, pathlib.PosixPath,

 

Make path using pathlib.

refer to code

..

from pathlib import Path
image_dir = 'dataset/images'
images = '1.png'
print(str(Path(image_dir) / images))
print( type(Path(image_dir) / images ))
# dataset/images/1.png
# <class 'pathlib.PosixPath'>

..


www.marearts.com