[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Create multiple directories

Paul Lemelle

2/25/2008 1:16:00 AM

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

7 Answers

Jeff Schwab

2/25/2008 1:27:00 AM

0

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? ")))

7stud --

2/25/2008 2:07:00 AM

0

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

Paul Rubin

2/25/2008 2:16:00 AM

0

7stud <bbxx789_05ss@yahoo.com> writes:
> 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

I find it's useful to keep all the filenames the same length and
put leading zeros in the directory numbers, so that sorting their
names lexicographically puts them in numerical order. Untested:

fmt = "new_dir%0%d" % len(str(num))
for i in xrange(num):
os.mkdir(fmt % i)

Or if num is unknown but you have some upper bound like 1000,
you could just use %05d or something like that.

Paul Rubin

2/25/2008 2:28:00 AM

0

Paul Rubin <http://phr.cx@NOSPAM.i... writes:
> fmt = "new_dir%0%d" % len(str(num))

Typo, that was supposed to say "new_dir%%0%d" ...

Paul Lemelle

2/25/2008 3:09:00 AM

0

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

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

Rich Rostrom

7/1/2014 8:47:00 PM

0

Rich Rostrom <rrostrom.21stcentury@rcn.com> wrote:

> The arguments against included:
>

And also:

5) Middle Eastern oil is in a place where
it can't be transported to Europe by the
Axis except in dribbles.

6) There are grave logistical difficulties
in deploying large Axis forces there.

7) "There is nothing in Africa worth the
bones of a single Pomeranian grenadier."
--
The real Velvet Revolution - and the would-be hijacker.

http://originalvelvetrevo...

synthius2002

7/2/2014 5:09:00 AM

0

On Sunday, June 29, 2014 9:06:24 AM UTC-4, Rich Rostrom wrote:
>
> 1) Destroying the USSR would deprive
>
> Britain of its only potential Continental
>
> ally, and cause Britain to give up.

I remember reading that this was the reason Hitler personally told folks for invading. I wouldn't know any details, but could imagine an incident further separating England and Russia politically, that makes a potential alliance look unlikely, remembering that looks count, since mr Hitler is not a pro, and given to puerile enthusiasms.

As for the actual strike south, I've always been interested in operation Felix, where the Germans try to take Gibraltar. Are there any African bases close enough for airborne? How big are defensive forces? Can special forces infiltrate through semi-neutral Spain? Were there reeeealy Italian navy special forces swimmers based in the port of Gibraltar?

We know the British thought it might happen. They had a plan for observers to be left behind in caves blasted shut that would take a very long time to dig out. They would have observation ports, radios, and lots and lots of supplies.

Nils K. Hammer