473,326 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Create multiple directories

I am somewhat new to Python and I am trying to create a program that
automatically creates directories from a range of numbers. I
researched the os.mkdir & os.makedirs methods, but they do not seem to
(I don't know) how to include an argumnet to step through my list.

I woudl like to do the follwoing:
1) Ask the user how many folders to create
2) take raw_input and then translate it into a while loop that steps
through the os.mkdir process.

Any would help would be appreicated.

Paul

Feb 25 '08 #1
4 4954
Paul Lemelle wrote:
I am somewhat new to Python and I am trying to create a program that
automatically creates directories from a range of numbers. I
researched the os.mkdir & os.makedirs methods, but they do not seem to
(I don't know) how to include an argumnet to step through my list.

I woudl like to do the follwoing:
1) Ask the user how many folders to create
2) take raw_input and then translate it into a while loop that steps
through the os.mkdir process.
Maybe something like this?

import os

def mkdirs(n):
for i in range(n):
os.mkdir("%d" % i)

if __name__ == '__main__':
mkdirs(int(raw_input("How many folders should I create? ")))
Feb 25 '08 #2
On Feb 24, 6:27*pm, Jeff Schwab <j...@schwabcenter.comwrote:
Paul Lemelle wrote:
I am somewhat new to Python and I am trying to create a program that
automatically creates directories from a range of numbers. I
researched the os.mkdir & os.makedirs methods, but they do not seem to
(I don't know) how to include an argumnet to step through my list.
I woudl like to do the follwoing:
1) Ask the user how many folders to create
2) take raw_input and then translate it into a while loop that steps
through the os.mkdir process.

Maybe something like this?

import os

def mkdirs(n):
* * *for i in range(n):
* * * * *os.mkdir("%d" % i)

if __name__ == '__main__':
* * *mkdirs(int(raw_input("How many folders should I create? ")))
Maybe something like this:

import os

num_str = raw_input("Enter number of dirs to create: ")
num = int(num_str)

for i in range(num):
dir_name = "new_dir%s" % i #same result as "new_dir" + str(i)
os.mkdir(dir_name) #creates dirs in current directory
Feb 25 '08 #3
Paul Rubin <http://ph****@NOSPAM.invalidwrites:
fmt = "new_dir%0%d" % len(str(num))
Typo, that was supposed to say "new_dir%%0%d" ...
Feb 25 '08 #4
7stud & Jeff,

Thanks for yoru input - there's still a few things for me to learn. :)
Paul

On Sun, 24 Feb 2008 18:07:15 -0800 (PST), 7stud
<bb**********@yahoo.comwrote:
>On Feb 24, 6:27*pm, Jeff Schwab <j...@schwabcenter.comwrote:
>Paul Lemelle wrote:
I am somewhat new to Python and I am trying to create a program that
automatically creates directories from a range of numbers. I
researched the os.mkdir & os.makedirs methods, but they do not seem to
(I don't know) how to include an argumnet to step through my list.
I woudl like to do the follwoing:
1) Ask the user how many folders to create
2) take raw_input and then translate it into a while loop that steps
through the os.mkdir process.

Maybe something like this?

import os

def mkdirs(n):
* * *for i in range(n):
* * * * *os.mkdir("%d" % i)

if __name__ == '__main__':
* * *mkdirs(int(raw_input("How many folders should I create? ")))

Maybe something like this:

import os

num_str = raw_input("Enter number of dirs to create: ")
num = int(num_str)

for i in range(num):
dir_name = "new_dir%s" % i #same result as "new_dir" + str(i)
os.mkdir(dir_name) #creates dirs in current directory
Feb 25 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: serge calderara | last post by:
Dear all, I have a library named Video.dll which provide certain vido functionnality as wel as menu and proprety using an interface. This library is working as a plugin Then I have my main...
2
by: krissh | last post by:
I know How Excel sheet in php .But wat i want is how to create Multiple sheets in Excel . This is the code for creating one excel sheet <?php header('Content-type:application/ms-xls'); ...
1
by: toramadevi | last post by:
Hi ALL, I 'm using DevC++ for writing a C source code to create multiple files and folders under a directory.With the help of mkdir command i am able to get a bunch of 40 folders in the current...
1
by: =?Utf-8?B?UGFkYW0=?= | last post by:
I created a user conrolt in C# and want to create multiple instance (one by one) of usercontrol onclick of button. if i hard code in .aspx page like <%@ Register...
3
by: DeanL | last post by:
Hi guys, Does anyone know of a way to create multiple tables using information stored in one table? I have a table with 4 columns (TableName, ColumnName, DataType, DataSize) and wanted to know...
1
by: chets92 | last post by:
sir i'm using sql as my backend and vb as my front end how can i create multiple users login...i' ve created a table in sql and accessing the name and password from there....can i do that for...
7
by: ChristinaTIT | last post by:
Hi, I have a form containing ID Type Quantity Rate values. it should have two submit buttons which, when posted, will do the two different things in two different scripts.
0
by: Fabian Svara | last post by:
Hi, I'm currently using tkFileDialog.askdirectory() to select a single directory. I would like to be able to select multiple directories. tkFileDialog.askopenfilenames() seems to do this for...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.