Create folder tree dynamically from a string
我正在编写代码,在代码中,我将根据从数据库中检索到的字符串创建文件夹和子文件夹。它是动态的,可以是一级,两级,或者十级。
我正在尝试用斜线替换点并创建正确的树,但下面的代码无法完成此任务:
1 2 3 | for x in i.publish_app.split('.'): if not os.path.isdir(os.path.join(settings.MEDIA_ROOT, PATH_CSS_DB_OUT) + x + '/'): os.mkdir(os.path.join(settings.MEDIA_ROOT, PATH_CSS_DB_OUT) + x + '/') |
例如,
我该怎么做?
1 | os.makedirs(path[, mode]) |
Recursive directory creation function.
Like mkdir(), but makes all
intermediate-level directories needed
to contain the leaf directory. Raises
an error exception if the leaf
directory already exists or cannot be
created. The default mode is 0777
(octal). On some systems, mode is
ignored. Where it is used, the current
umask value is first masked out.
直接从医生那里。
使用
你为什么不做:
(最后一个