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

damjohnron

New member
Local time
6:01 PM
Messages
3
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 My Computer

Computer Manufacturer/Model Number
Dell latitude
OS
windows 7 32
CPU
2.2
Motherboard
dont care
Memory
4 gb
Graphics Card(s)
nvidia
Monitor(s) Displays
quad monitor 1909 widescreen x3 laptop display used as well
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 My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Toshiba Laptop Qosimo X870
OS
Windows 7 Pro x64 SP1
CPU
Intel Core I7
Motherboard
Toshiba Qosmio
Memory
16 Gigs
Graphics Card(s)
NVIDIA GeForce GTX 670M
Monitor(s) Displays
17.7" laptop
Screen Resolution
1600 x 900
Hard Drives
256 Gig SanDisk SSD for C
256 Gig Intel SSD for D
Internet Speed
50/25 FIOS
Antivirus
Vipre (all you can eat for 10 machines)
Browser
IE and FF
Other Info
I have dos 6.22, wfwg 3.11, win98, 2000 and xp VHD's available for testing. MS's Virtual PC works great.
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 My Computer

Computer Manufacturer/Model Number
Dell latitude
OS
windows 7 32
CPU
2.2
Motherboard
dont care
Memory
4 gb
Graphics Card(s)
nvidia
Monitor(s) Displays
quad monitor 1909 widescreen x3 laptop display used as well
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 My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Toshiba Laptop Qosimo X870
OS
Windows 7 Pro x64 SP1
CPU
Intel Core I7
Motherboard
Toshiba Qosmio
Memory
16 Gigs
Graphics Card(s)
NVIDIA GeForce GTX 670M
Monitor(s) Displays
17.7" laptop
Screen Resolution
1600 x 900
Hard Drives
256 Gig SanDisk SSD for C
256 Gig Intel SSD for D
Internet Speed
50/25 FIOS
Antivirus
Vipre (all you can eat for 10 machines)
Browser
IE and FF
Other Info
I have dos 6.22, wfwg 3.11, win98, 2000 and xp VHD's available for testing. MS's Virtual PC works great.
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 "[B]-WhatIf[/B]" in the line below to allow the directories to be created
    New-Item -Path $path -ItemType 'Directory' -WhatIf
    $n++
}
 

My Computer My Computer

OS
Windows 7 Pro x64
Back
Top