operating system - Python OS mkdir (create folders with looping a list) -


I'm trying to create a folder using os.mkdir with looping on the list for example i Want 12 folders with name, January, February ... etc Month = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November" "December"] for months in the months: os.mkdir ('D: \\ Python_GIS')

With this in the way many lines I could make folders I wanted. P>

  import os om.mkdir ('D: \\ Python_GIS \' Jan ') os.mkdir (' D: \\ Python_GIS \\ ('D: \\ Python_GIS \' March ') OSMKDR ('D: \\ Python_GIS \ app') OSMKDR ('D: \\ Python_GIS \') '' OS Mkdir ('D: \\ Python_GIS \\ Jun') os.mkdir ('D: \\ Python_G IS \\ July ') os.mkdir (' D: \\ Python_GIS \\ Aug ') os.mkdir (' D: \\ Python_GIS \\ Sep ') os.mkdir (' D: \\ Python_GIS \\ Oct ' ) Os.mkdir ('D: \\ Python_GIS \\ Nov') os.mkdir ('D: \\ Python_GIS \\ December')  

But with no looping to do it

Thanks

this os.path.join ( ) is a major task that adds logic to the system's separator. This is a great way to reduce errors related to \ .

DD: "D: \\ Python_GIS" for months in months: os.makedir (OS. Path.join (baseDir, month))

Unrelated style Note: Try setting your path as a raw wire which will ignore the texts, so baseDir = r'D: \ Python_GIS '


Comments