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
damjohnron

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
richnrockville

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
damjohnron

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
richnrockville

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
fiddler

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
Thread Forum
Windows 7 creating blank txt file after running a batch script
I have the following batch script @echo off setlocal enableextensions set "baseName=dnshistory" set "count=0" for /f "delims=%baseName%." %%a in (
General Discussion
Creating a batch script or use a 3rdpartyprogram to create shortcuts
Hello! I'm having trouble creating a batch script to simply copy a shortcut to the desktop from a program installation, then carry out some tasks. Overall my goals are: Burn a CD that includes a autorun.inf that will load a batch script In the script I want it to activate two self...
General Discussion
PDF file association REG or Batch Script
At work i use 2 different PDF viewing software. One is Adobe for editing and the other is Foxit for quick viewing. They have their pros and cons and so I use them interchangeably. For some work I will use Foxit for several hours at a time and only open something in Adobe on an as needed basis...
Software
File search (by date range) displays incorrect Mod Date in results
Searching for files modified in a specified date range (of the past 3 days) gets a search result list titled "date modified", and with the column heading "Date Modified" but the date listed against a file modified today is wrong. The date displayed matches the file creation date & is within the...
General Discussion
How to create a current date folder using batch file?
Hi I am using following batch file for cleaning the desktop and also for taking backup of desktop: @echo off set curr_date=%DATE:~10,4%-%DATE:~4,2%-%DATE:~7,2% mkdir "%USERPROFILE%\My Documents\backup\%curr_date%_backup"
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 13:14.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App