الفرق بين المراجعتين لصفحة: «Python/pathlib/Path/mkdir»
أنشأ الصفحة ب'== التابع Path.cwd == يعيد كائن مسار جديدًا يمثّل المسار الحالي (بشكل مشابه للتابع os.getcwd)<syntaxhighlight lan...' |
|||
سطر 1: | سطر 1: | ||
== التابع Path. | == التابع Path.mkdir == | ||
Create a new directory at this given path. If mode is given, it is combined with the process’ umask value to determine the file mode and access flags. If the path already exists, FileExistsError is raised. | |||
If parents is true, any missing parents of this path are created as needed; they are created with the default permissions without taking mode into account (mimicking the POSIX mkdir -p command). | |||
If parents is false (the default), a missing parent raises FileNotFoundError. | |||
If exist_ok is false (the default), FileExistsError is raised if the target directory already exists. | |||
If exist_ok is true, FileExistsError exceptions will be ignored (same behavior as the POSIX mkdir -pcommand), but only if the last path component is not an existing non-directory file. | |||
Changed in version 3.5: The exist_ok parameter was added.<syntaxhighlight lang="python3"> | |||
>>> p=Path(r"D:\Users\MOUSTAFA\Desktop\my_folder") | |||
>>> p | |||
WindowsPath('D:/Users/MOUSTAFA/Desktop/my_folder') | |||
>>> p.exists() | |||
False#المسار المحدد غير موجود في نظام الملفات | |||
>>> p.mkdir() | |||
>>> p.exists() | |||
True#تم إنشاء الملف في نظام الملفات | |||
</syntaxhighlight><span> </span> | </syntaxhighlight><span> </span> |
مراجعة 07:19، 3 أغسطس 2018
التابع Path.mkdir
Create a new directory at this given path. If mode is given, it is combined with the process’ umask value to determine the file mode and access flags. If the path already exists, FileExistsError is raised.
If parents is true, any missing parents of this path are created as needed; they are created with the default permissions without taking mode into account (mimicking the POSIX mkdir -p command).
If parents is false (the default), a missing parent raises FileNotFoundError.
If exist_ok is false (the default), FileExistsError is raised if the target directory already exists.
If exist_ok is true, FileExistsError exceptions will be ignored (same behavior as the POSIX mkdir -pcommand), but only if the last path component is not an existing non-directory file.
Changed in version 3.5: The exist_ok parameter was added.
>>> p=Path(r"D:\Users\MOUSTAFA\Desktop\my_folder")
>>> p
WindowsPath('D:/Users/MOUSTAFA/Desktop/my_folder')
>>> p.exists()
False#المسار المحدد غير موجود في نظام الملفات
>>> p.mkdir()
>>> p.exists()
True#تم إنشاء الملف في نظام الملفات