Is there a Script or batch file that can create folders by date range


  1. Posts : 3
    windows 7 32
       #1

    Is there a Script or batch file that can create folders by date range


    I was wondering if there was a way to create a set of folders in a specific directory according to a date range that i input.

    ie.

    Select start date 2011 10 01

    select end date 2012 10 01

    Select Output path of c:\users\XXXX\desktop\export data

    and it creates a folder for all days from 2011 10 01 through 2012 10 01 and places them in the output path i have set for it.

    any help would be greatly appreciated.

    Thank you
      My Computer


  2. Posts : 1,800
    Windows 7 Pro x64 SP1
       #2

    Welcome damjohnron to the windows 7 forums.

    Here are some snippits of a dos batch file that will create a directory with the datek and tell you if it already exists.


    set DATEST=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%
    echo %datest%
    rem if it looks ok, then you can press enter to continue
    pause
    if exist %homepath%\documents\%datest% goto dup1
    md %homepath%\documents\%datest%
    rem the pause can be taken out if you wish.
    pause
    go to end
    :dup1
    rem you already have done this.
    pause
    :end

    you can change the path statement to the directory you wish.

    This batch file can be run each day that you want to create a new sub directory.
    There are other ways to do this but a bit more complicated such as reading an external
    text file for the directory names.

    Rich
      My Computer


  3. Posts : 3
    windows 7 32
    Thread Starter
       #3

    Thank you for your response on this.

    i believe that i have not explained this sitaution correctly

    the results that i would like to do is set a date range ie. 10/01/2011 - 10/01/2012
    and have a folder created for every day in that date range.

    10/1/2011
    10/2/2011
    10/3/2011
    ...
    ...
    ...
    ...
    9/28/2012
    9/29/2012
    9/30/2012
    10/1/2012

    I do apologize for any confusion on my description of this issue.

    Thank you
    John
      My Computer


  4. Posts : 1,800
    Windows 7 Pro x64 SP1
       #4

    John, one problem with your requirements is that each month only goes to 28-29-30-31 so a counter would not work, Also the / marks won't work in a file or dir name.

    you could create a text file with all the dates that you want and then read it, create a powershell script that will read the file and make the directory.
    You might want to look into powershell which is in the accessories/powershell start panel.

    I am sure that it is possible. I could do it in gwbasic pretty easily but I am not conversant in powershell.

    Rich
      My Computer


  5. Posts : 3
    Windows 7 Pro x64
       #5

    Try this, in Powershell.

    Code:
    $n = 0
    $dest = Join-Path $env:USERPROFILE '\Desktop\Export Data'
    
    $firstDate = '2011/10/01'
    $lastDate = '2012/10/01'
    
    While ( ( Get-Date $firstDate ).AddDays( $n ) -le ( Get-Date $lastDate ) ) {
        $path = Join-Path $dest ( Get-Date $firstDate ).AddDays( $n ).ToString( 'yyyy-MM-dd' )
        # REMOVE the "-WhatIf" in the line below to allow the directories to be created
        New-Item -Path $path -ItemType 'Directory' -WhatIf
        $n++
    }
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 18:29.
Find Us