Showing posts with label os. Show all posts
Showing posts with label os. Show all posts

4/13/2023

Create the output folder if it doesn't exist, python example

 refer to code:


.

# Create the output folder if it doesn't exist
output_folder = os.path.dirname(ioutput_file)
os.makedirs(output_folder, exist_ok=True)

..


Thank you.

πŸ™‡πŸ»‍♂️

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

10/02/2022

python os mkdir example code

..

if not os.path.exists(output_dir):
    os.mkdir(output_dir)

..


Thank you.

www.marearts.com

8/26/2022

finding all specific extension file in all subfolder from starting directory

 refer to example code

..

import os
from glob import glob

start_dir = '/start/folder' #os.getcwd()
pattern = "*.jpg" #file extension which you want to find

for dir,_,_ in os.walk(start_dir):
print( glob(os.path.join(dir,pattern)) )

..


Thank you.

www.marearts.com