0

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.

abby
  • 1
  • 1
  • 2

2 Answers2

0

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

d3javu999
  • 323
  • 1
  • 8
  • thanks for replying. Could you please share some code or something else as I need to do create folder in web page. Thanks! – abby May 11 '22 at 18:25
  • https://stackoverflow.com/questions/273192/how-can-i-safely-create-a-nested-directory – d3javu999 May 11 '22 at 18:26
0

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)
aestet
  • 314
  • 1
  • 3
  • 13
  • thank you. I need to create in the web page. I can tap create folder and set the name of the folder, after that I can move some files there – abby May 11 '22 at 18:26