Windows Vista Forums

Copy files based upon Create Date

  1. #1


    AHartman Guest

    Copy files based upon Create Date

    I need to have a process that looks at a Network shared folder
    \\Archive\datafiles and based upon file date creation create another folder
    within this structure to move them to.

    example..

    files in folder \\Archive\datafiles

    abc.xls 1/5/08
    def.xls 1/15/08
    ghi.chs 1/20/08
    com1.xls 2/2/08
    com4.xls 2/5/08


    After script runs new folders created

    \\Archive\datafiles\Jan08
    \\Archive\datafiles\Feb08


    Then inside \\Archive\datafiles\Jan08

    abc.xls 1/5/08
    def.xls 1/15/08
    ghi.chs 1/20/08


    \\Archive\datafiles\Feb08

    com1.xls 2/2/08
    com4.xls 2/5/08


    They are no longer on the root \\Netstore\datafiles but inside there Monthly
    folder. This process will run the 1st day of the new month to grab what will
    be last months files. I need this script to catch up the process.




    Thanks.


      My System SpecsSystem Spec

  2. #2


    Join Date : May 2008
    Posts : 88
    Vista Home Premium 32bit
    Local Time: 02:25 AM
    italy

     

    Re: Copy files based upon Create Date

    You can create the different folders in this way

    gci | % {$_.creationtime.tostring("MMMyy")} | sort | get-unique | % {md $_}

    then you can create two array, one for the files and one for the folders

    $folders = gci | ? {$_.psiscontainer}
    $files = gci | ? {-not $_.psiscontainer}

    and finally you can loop each file and compare it with the folder name

    foreach ($file in $files) {foreach($folder in $folders) {if($file.creationtime.tostring("MMMyy") -eq $folder) {copy-item $file -destination $folder}}}

    if everything works well you can use move-item instead of copy-item.

      My System SpecsSystem Spec

  3. #3


    AHartman Guest

    Re: Copy files based upon Create Date


    Can this also be logged so at the end of the process you get

    xxx files copied to xxxfolder


    "sardinian_guy" <guest@xxxxxx-email.com> wrote in message
    news:5c1e6e75582755ccf75dafec3675fa0f@xxxxxx-gateway.com...

    >
    > You can create the different folders in this way
    >
    > gci | % {$_.creationtime.tostring("MMMyy")} | sort | get-unique | % {md
    > $_}
    >
    > then you can create two array, one for the files and one for the
    > folders
    >
    > $folders = gci | ? {$_.psiscontainer}
    > $files = gci | ? {-not $_.psiscontainer}
    >
    > and finally you can loop each file and compare it with the folder name
    >
    > foreach ($file in $files) {foreach($folder in $folders)
    > {if($file.creationtime.tostring("MMMyy") -eq $folder) {copy-item $file
    > -destination $folder}}}
    >
    > if everything works well you can use move-item instead of copy-item.
    >
    >
    > --
    > sardinian_guy

      My System SpecsSystem Spec

Copy files based upon Create Date

Similar Threads
Thread Thread Starter Forum Replies Last Post
powershell script help - recursive delete based on modified date PowerShell 1 12 Nov 2008
Deleteing Files in a folder based on date! wiseteufel via WindowsKB.com Vista file management 2 10 Sep 2008
I want to create a PC based email account giuseppe Vista mail 3 13 Feb 2008
Delete files based on last accessed date? steveb PowerShell 3 23 Jul 2007
Delete based on date Woody UK PowerShell 3 13 Sep 2006