Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Creating Multiple Directories  (Read 6184 times)

0 Members and 1 Guest are viewing this topic.

JPSherwin

    Topic Starter


    Starter

    • Experience: Experienced
    • OS: Windows XP
    Creating Multiple Directories
    « on: September 09, 2011, 10:28:49 AM »
    Monthly I go through a process of creating 36 directories.  I thought a DOS batch/command file would be an easier way of doing this than clicking through Windows, multiple times.  The naming convention of these directories only changes monthly by the month name and annually by the fiscal year.  Here is an example of what I tried.

         MKDIR H:\Acct COE\AR Chapter\FY 2012\Maine\SO Maine-Portland\Backup-September 2011
         MKDIR H:\Acct COE\AR Chapter\FY 2012\Maine\SO Maine-Portland\Backup-September 2011\Posting Reports

    What I got was not what I need.  (1) the directories created were created under My Documents rather than drive H: (which is a network drive).  (2) rather than 2 directories, as set forth above, I got 10 directories (as a result of the spaces in the drectory names above).

    So, I have the following questions:

    Using a DOS batch/command file,
     - Can I create directories on a network drive?

     - If I am able to do so, could you explain what is wrong with the above command or what I need to add to accomplish this.
     
     - If memory serves me correctly DOS directories did not allow for spaces in the directory name (used a lot of hyphens and underscores).  Is there a work around?
     
     - If what I'm trying to accomplish cannot be accomplished with a DOS batch/command file, is there an alternative approach?
     
    Thanks in advance for your help.

    Salmon Trout

    • Guest
    Re: Creating Multiple Directories
    « Reply #1 on: September 09, 2011, 11:17:32 AM »
    Can I create directories on a network drive?

    Is it a mapped drive?
     
    Quote
    If memory serves me correctly DOS directories did not allow for spaces in the directory name (used a lot of hyphens and underscores).  Is there a work around?

    (a) If you using a recent version of Windows (2000, XP, Vista, 7) this isn't "DOS".
    (b) In the Windows NT family command environment, paths, and folder and file names with spaces need quote marks e.g.:

    mkdir "S:\Folder 1\Folder 2\Folder 3"

     

    JPSherwin

      Topic Starter


      Starter

      • Experience: Experienced
      • OS: Windows XP
      Re: Creating Multiple Directories
      « Reply #2 on: September 09, 2011, 12:04:55 PM »
      Thank you.  Your point of quotes around the path worked.  I was able to create the directories.

      I'm using XP Pro V2002 SP3.  If the batch commands I'm using aren't DOS what are they?

      As for the drive being mapped,  I believe it is.  When I click on the My Computer icon on my Desktop, the drive on which I want to establish these directories is among those listed.

      Thank you once again for your help.

      Salmon Trout

      • Guest
      Re: Creating Multiple Directories
      « Reply #3 on: September 09, 2011, 12:59:01 PM »
      I'm using XP Pro V2002 SP3.  If the batch commands I'm using aren't DOS what are they?

      Well, in a nutshell, MS-DOS was (is) an operating system, which has a command interpeter, COMMAND.COM, whereas cmd.exe is the Windows NT family command interpreter.

      MS-DOS, sometimes abbreviated to "DOS", is a 16-bit command line operating system introduced in 1981 which ran through versions 1 to 6 (version 6.22 released 1992) and a version 7 which accompanied Windows 95, 98 and ME. It has "8.3" upper case  filenames. It has a batch language. Its command interpreter is a 16-bit MS-DOS program called COMMAND.COM.

      During the 1990s Microsoft also marketed a business-oriented GUI operating system called Windows NT. This also had a command interpreter, called cmd.exe (or CMD.EXE if you like). The batch language was broadly backwards compatible with COMMAND.COM and used similar syntax and conventions. Successive versions of cmd.exe accompanied the NT family (NT 3.51, NT4, Windows 2000, Server 2003, Windows Vista, Server 2008,  Windows 7) and its features grew. The version which came with Windows 2000 is broadly what we see today. It has a sufficient number of features and commands which are absent from MS-DOS that it is correctly regarded as a completely different environment than COMMAND.COM.

      Regarding the network drive issue, you may find this page useful:

      http://answers.yahoo.com/question/index?qid=20060921072945AAGOgzH

      Raven19528



        Hopeful
      • Thanked: 30
        • Computer: Specs
        • Experience: Experienced
        • OS: Windows 7
        Re: Creating Multiple Directories
        « Reply #4 on: September 09, 2011, 05:06:18 PM »
        Here is an example of what I tried.

             MKDIR H:\Acct COE\AR Chapter\FY 2012\Maine\SO Maine-Portland\Backup-September 2011
             MKDIR H:\Acct COE\AR Chapter\FY 2012\Maine\SO Maine-Portland\Backup-September 2011\Posting Reports

        A few things that you can do here to make this work out better for you. First, if at all possible to do so, I would try to change the naming convention if at all possible to use numbered months after "Backup", you'll see why in a minute. Second, it would be a lot easier to have the program prompt for certain things (like what FY it is) and then the rest of it can be hardcoded (much better than having to change the script every month). Anyway, here's the coding for setting up a prompt for the fiscal year:

        echo Please enter the current fiscal year
        set /p fy=(FY)

        This will have the program spit out:

        Please enter the current fiscal year
        FY |

        With the I being where the cursor would be.

        Also, if you want to make sure that your putting it in the right location, you can put the following at an early point in the script:

        net use H: /delete /y
        net use H: [full network location] /persistent:yes

        This will delete the network location on H: and then remap it to the H: drive you wish to utilize.

        Now comes the time to make the actual directories:

        MKDIR "H:\Acct COE\AR Chapter\FY %fy%\Maine\SO Maine-Portland\Backup-%date:~10%%date:~4,2%"
        MKDIR "H:\Acct COE\AR Chapter\FY %fy%\Maine\SO Maine-Portland\Backup-%date:~10%%date:~4,2%\Posting Reports"

        You'll notice the coding using the date variable in there as well. This will spit out the date the directory is made in a yyyymm format. So you'll end up with a file named "Backup-201109". You can adjust the layout of the date variables a little, and I'm sure you could likely use an additional piece of code to rewrite the month from numbers to letters if you wanted to. We can help out with that, but it would be up to you whether it is easier to change the naming convention or put in an even more involved piece of code in.
        « Last Edit: September 09, 2011, 05:34:26 PM by Raven19528 »
        "All things that are
        Are with more spirit chased than enjoy'd" -Shakespeare

        Raven19528



          Hopeful
        • Thanked: 30
          • Computer: Specs
          • Experience: Experienced
          • OS: Windows 7
          Re: Creating Multiple Directories
          « Reply #5 on: September 12, 2011, 10:56:28 AM »
          I thought on it a little bit and here's how you can make it work:

          if "%date:~4,2%"=="01" set month=January
          if "%date:~4,2%"=="02" set month=February
          ...
          if "%date:~4,2%"=="12" set month=December


          Then where the mkdir commands are:

          mkdir "H:\Acct COE\AR Chapter\FY %fy%\Maine\SO Maine-Portland\Backup-%month% %date:~10%"
          mkdir "H:\Acct COE\AR Chapter\FY %fy%\Maine\SO Maine-Portland\Backup-%month% %date:~10%\Posting Reports"

          So there you go, hope that all helps.
          "All things that are
          Are with more spirit chased than enjoy'd" -Shakespeare

          Raven19528



            Hopeful
          • Thanked: 30
            • Computer: Specs
            • Experience: Experienced
            • OS: Windows 7
            Re: Creating Multiple Directories
            « Reply #6 on: September 13, 2011, 09:58:07 AM »
            Just in case you were looking for a little bit more automation, here's how you can set your FY without input:

            if /i %date:~4,2% geq 10 (
              set /a fy=%date:~10%+1
            ) else (
              set fy=%date:~10%
            )
            "All things that are
            Are with more spirit chased than enjoy'd" -Shakespeare

            JPSherwin

              Topic Starter


              Starter

              • Experience: Experienced
              • OS: Windows XP
              Re: Creating Multiple Directories
              « Reply #7 on: September 27, 2011, 06:43:55 AM »
              Salmon Trout

              Thank you for the information.  I was able to accomplish what I wanted.

              Raven19528

              Thank you for the suggestion.  However, I am not able to change from Month Name to Month Number.  It's too engrained with my colleagues.

              Raven19528



                Hopeful
              • Thanked: 30
                • Computer: Specs
                • Experience: Experienced
                • OS: Windows 7
                Re: Creating Multiple Directories
                « Reply #8 on: September 29, 2011, 08:46:26 AM »
                Yes, I work with some of the same types of people. Ones who have been doing things one way for so long that any change makes them scream in outrage or retire.  ::)

                For the coding, just put together the many small posts and you get the code you are looking for:
                Code: [Select]
                ...
                net use H: /delete /y
                net use H: [full network location] /persistent:yes

                if "%date:~4,2%"=="01" set month=January
                if "%date:~4,2%"=="02" set month=February
                if "%date:~4,2%"=="03" set month=March
                if "%date:~4,2%"=="04" set month=April
                if "%date:~4,2%"=="05" set month=May
                if "%date:~4,2%"=="06" set month=June
                if "%date:~4,2%"=="07" set month=July
                if "%date:~4,2%"=="08" set month=August
                if "%date:~4,2%"=="09" set month=September
                if "%date:~4,2%"=="10" set month=October
                if "%date:~4,2%"=="11" set month=November
                if "%date:~4,2%"=="12" set month=December

                if /i %date:~4,2% geq 10 (
                  set /a fy=%date:~10%+1
                ) else (
                  set fy=%date:~10%
                )

                mkdir "H:\Acct COE\AR Chapter\FY %fy%\Maine\SO Maine-Portland\Backup-%month% %date:~10%"
                mkdir "H:\Acct COE\AR Chapter\FY %fy%\Maine\SO Maine-Portland\Backup-%month% %date:~10%\Posting Reports"
                ...

                The best thing about the code now is that there is no need for user input so it takes that human factor out of the equation.
                "All things that are
                Are with more spirit chased than enjoy'd" -Shakespeare