Create multiple directories

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul Lemelle

    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

  • Jeff Schwab

    #2
    Re: Create multiple directories

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

    Comment

    • 7stud

      #3
      Re: Create multiple directories

      On Feb 24, 6:27 pm, Jeff Schwab <j...@schwabcen ter.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("Ente r 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_na me) #creates dirs in current directory

      Comment

      • Paul Rubin

        #4
        Re: Create multiple directories

        Paul Rubin <http://phr.cx@NOSPAM.i nvalidwrites:
        fmt = "new_dir%0% d" % len(str(num))
        Typo, that was supposed to say "new_dir%%0 %d" ...

        Comment

        • Paul Lemelle

          #5
          Re: Create multiple directories

          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@y ahoo.comwrote:
          >On Feb 24, 6:27 pm, Jeff Schwab <j...@schwabcen ter.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("Ente r 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_na me) #creates dirs in current directory

          Comment

          Working...