Need some help with a batch file to creating sub-folders in a directory

Posted on 2014-08-28
Last Modified: 2014-09-02

I have some reports that I save on a network share.  There is a report for every calendar date and I want each report in its own sub folder.  We'll be manually saving the reports to the share after download.  

Is there a way to create a batch file that would automatically create these sub-folders using the naming convention of "MMDDYY".  I am looking to avoid having my users manually create a new folder every day.

Question by:mike-9
    LVL 5

    Accepted Solution

    Try this snippet, use what you need:
    @echo off
    for /f "delims=" %%a in ('wmic OS Get localdatetime  ^| find "."') do set dt=%%a
    set datestamp=%dt:~0,8%
    set timestamp=%dt:~8,6%
    set YYYY=%dt:~0,4%
    set MM=%dt:~4,2%
    set DD=%dt:~6,2%
    set HH=%dt:~8,2%
    set Min=%dt:~10,2%
    set Sec=%dt:~12,2%

    set stamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%
    echo stamp: "%stamp%"
    echo datestamp: "%datestamp%"
    echo timestamp: "%timestamp%"

    LVL 24

    Assisted Solution

    Do you want a daily batch file to run and create the folders for you so that each day the folders and sub folders are created on a server share or do you it created on each user's PC when they logon that day?

    Author Comment

    I was looking for a daily or even monthly batch file to create the folders and sub folders on a server share.

    I wound up finding a solution that worked for me.  It is simplistic.

    I wound up just using excel to create the folder structure.  Column A was the MD command.  Column B was my folder.  Column C was a sub folder.  Column D was my date.  It was easy to drag down the column to get my consecutive dates.  I exported the whole thing as a text file and ran it as a batch.  

    It's not completely automated but I could set up a decade of folders in a few minutes.  

    I'm going to check out SemperPhi's solution just to increase my knowledge of the subject.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Hallo! I guess almost every Windows Administrator must have got stumped with this question "Where does WINDOWS store a users cached credentials? Every user who had once logged onto a Server/Desktop while it was connected to the domain could sti…
    by Nathan Brom/Bromy2004 Introduction There are numerous websites out there for any different type of program you can imagine.  Of those, you'll need to decide which ones are legitimate and aren't trying to steal your money or infect your comput…
    This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
    Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now