Home > Blockchain >  Create folder and subfolder with django app
Create folder and subfolder with django app

Time:05-12

Maybe this is to trivial question, but please assist me. How can I create folder and subfolder in it with django python. When I google I just get some information about folder structure, but it is not what I am looking for. Please share some code examples if it is possible

Many thanks.

CodePudding user response:

why don't look up for how to create folders and subfolders with python using the subprocess or os ?

the ok command (linux and macos) is mkdir -p /path/you/want

CodePudding user response:

You don't need much more:

import os
# creating subfolder in the directory of launched script
os.makedirs("subfolder", exist_ok=True)
# constructing full absolute path to project_folder
ROOT_FOLDER = os.path.abspath(__file__)
print(ROOT_FOLDER)
# joining root_folder and subfolder in order to create\work with files in nested folders
subfolder_abs_path = os.path.join(ROOT_FOLDER, 'subfolder')
print(subfolder_abs_path)
  • Related