ฟังก์ชั่น mkdir เป็นฟังก์ชั่นสำหรับการสร้าง folder ด้วย ภาษา
python โดยใช้
library os ขั้นตอนการทำคือ
1.
import os
2.สร้างตัวแปร กำหนดที่อยู่
โค้ด: เลือกทั้งหมด
app_path = os.path.dirname(os.path.abspath(__file__))
3.เขียนเพื่อกำหนด ว่าที่นั้น มี โฟเดอร์ images
โค้ด: เลือกทั้งหมด
target = os.path.join ( app_path, "images/" )
4.ถ้าไม่มีจะทำการสร้างใหม่
โค้ด: เลือกทั้งหมด
if not os.path.isdir ( target ):
os.mkdir ( target )
ผลลัพธ์
- Python Knowledge-1.png (4.33 KiB) Viewed 661 times
- Python Knowledge-2.png (3.54 KiB) Viewed 661 times
อ้างอิง
https://docs.python.org/3/library/os.html
https://www.geeksforgeeks.org/os-walk-python/
https://www.pythonforbeginners.com/code-snippets-source-code/python-os-walk
ฟังก์ชั่น mkdir เป็นฟังก์ชั่นสำหรับการสร้าง folder ด้วย ภาษา [url=https://www.mindphp.com/%E0%B8%84%E0%B8%B9%E0%B9%88%E0%B8%A1%E0%B8%B7%E0%B8%AD/73-%E0%B8%84%E0%B8%B7%E0%B8%AD%E0%B8%AD%E0%B8%B0%E0%B9%84%E0%B8%A3/2417-python-%E0%B8%84%E0%B8%B7%E0%B8%AD%E0%B8%AD%E0%B8%B0%E0%B9%84%E0%B8%A3.html]python[/url] โดยใช้ [url=https://www.mindphp.com/forums/viewtopic.php?f=29&t=42917]library[/url] os ขั้นตอนการทำคือ
1. [url=https://www.mindphp.com/%E0%B8%9A%E0%B8%97%E0%B9%80%E0%B8%A3%E0%B8%B5%E0%B8%A2%E0%B8%99%E0%B8%AD%E0%B8%AD%E0%B8%99%E0%B9%84%E0%B8%A5%E0%B8%99%E0%B9%8C/83-python/2495-%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%83%E0%B8%8A%E0%B9%89-from-import-modules.html]import[/url] os
[code]import os[/code]
2.สร้างตัวแปร กำหนดที่อยู่
[code]app_path = os.path.dirname(os.path.abspath(__file__))[/code]
3.เขียนเพื่อกำหนด ว่าที่นั้น มี โฟเดอร์ images
[code]target = os.path.join ( app_path, "images/" )[/code]
4.ถ้าไม่มีจะทำการสร้างใหม่
[code] if not os.path.isdir ( target ):
os.mkdir ( target )[/code]
ผลลัพธ์
[attachment=1]Python Knowledge-1.png[/attachment]
[attachment=0]Python Knowledge-2.png[/attachment]
อ้างอิง
https://docs.python.org/3/library/os.html
https://www.geeksforgeeks.org/os-walk-python/
https://www.pythonforbeginners.com/code-snippets-source-code/python-os-walk