Windows Vista Forums

Creating a dated directory
  1. #1


    tERRY Guest

    Creating a dated directory

    I'm a scripting and PowerShell newbie. I have a daily requirement to create a
    directory with yesterday's date. I wrote a function to calculate yesterday's
    date and put it in the variable, $yesterday. I can't figure out how to
    extract the date as a string and insert it in the new-item cmdlet to create
    the directory. Does anyone have any suggestions?
    --
    Terry Edwards



      My System SpecsSystem Spec

  2. #2


    Karl Mitschke Guest

    Re: Creating a dated directory

    Hello Terry,

    Something like this will work:

    $date = ( get-date ).AddDays(-1).ToString('yyyyMMdd')
    mkdir "c:\$date"

    > I'm a scripting and PowerShell newbie. I have a daily requirement to
    > create a directory with yesterday's date. I wrote a function to
    > calculate yesterday's date and put it in the variable, $yesterday. I
    > can't figure out how to extract the date as a string and insert it in
    > the new-item cmdlet to create the directory. Does anyone have any
    > suggestions?
    >


      My System SpecsSystem Spec

  3. #3


    tERRY Guest

    Re: Creating a dated directory

    Thanks, Karl. It worked. How do you find out about the ".AddDays" and
    ".ToString" functions?
    --
    Terry Edwards


    "Karl Mitschke" wrote:

    > Hello Terry,
    >
    > Something like this will work:
    >
    > $date = ( get-date ).AddDays(-1).ToString('yyyyMMdd')
    > mkdir "c:\$date"
    >

    > > I'm a scripting and PowerShell newbie. I have a daily requirement to
    > > create a directory with yesterday's date. I wrote a function to
    > > calculate yesterday's date and put it in the variable, $yesterday. I
    > > can't figure out how to extract the date as a string and insert it in
    > > the new-item cmdlet to create the directory. Does anyone have any
    > > suggestions?
    > >
    >
    >
    >

      My System SpecsSystem Spec

  4. #4


    Karl Mitschke Guest

    Re: Creating a dated directory

    Hello Terry,

    $date = ( get-date )
    $date |gm





    > Thanks, Karl. It worked. How do you find out about the ".AddDays" and
    > ".ToString" functions?
    >
    > "Karl Mitschke" wrote:
    >

    >> Hello Terry,
    >>
    >> Something like this will work:
    >>
    >> $date = ( get-date ).AddDays(-1).ToString('yyyyMMdd') mkdir
    >> "c:\$date"
    >>

    >>> I'm a scripting and PowerShell newbie. I have a daily requirement to
    >>> create a directory with yesterday's date. I wrote a function to
    >>> calculate yesterday's date and put it in the variable, $yesterday. I
    >>> can't figure out how to extract the date as a string and insert it
    >>> in the new-item cmdlet to create the directory. Does anyone have any
    >>> suggestions?
    >>>


      My System SpecsSystem Spec

Creating a dated directory problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Question for creating a directory file Using Vista Ultimate.. jumpstreet General Discussion 6 17 Nov 2008
creating or pasting a directory in Windows Explorer Mitch Vista installation & setup 0 11 Jan 2008
Creating a list of files that have been deleted from or added to a directory hrh1818 PowerShell 5 11 Oct 2007
creating files in the system directory Jeff McKay Vista file management 3 03 Apr 2007
re: creating files in the system directory Jeff McKay Vista file management 0 03 Mar 2007