Create multiple directories

Paul Lemelle Plemelle at comcast.net
Mon Feb 25 04:09:12 CET 2008


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
<bbxx789_05ss at yahoo.com> wrote:

>On Feb 24, 6:27 pm, Jeff Schwab <j... at schwabcenter.com> wrote:
>> 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




More information about the Python-list mailing list