Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


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


02 Jul 2012   #1

windows 7 32
 
 
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 System SpecsSystem Spec
.

02 Jul 2012   #2

Windows 7 Pro x64 SP1
 
 

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 System SpecsSystem Spec
02 Jul 2012   #3

windows 7 32
 
 

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 System SpecsSystem Spec
.


02 Jul 2012   #4

Windows 7 Pro x64 SP1
 
 

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 System SpecsSystem Spec
04 Jul 2012   #5

Windows 7 Pro x64
 
 

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 System SpecsSystem Spec
Reply

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




Thread Tools



Similar help and support threads for2: Is there a Script or batch file that can create folders by date range
Thread Forum
Creating a batch script or use a 3rdpartyprogram to create shortcuts General Discussion
How to create batch script to lock workstation then log off. General Discussion
PDF file association REG or Batch Script Software
File search (by date range) displays incorrect Mod Date in results General Discussion
Solved How to create a current date folder using batch file? General Discussion
batch file to create a daily date folder General Discussion

Our Sites

Site Links

About Us

Find 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 06:00 AM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33