Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Copy files based upon Create Date

Reply
 
Old 07-22-2008   #1 (permalink)
AHartman


 
 

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
Old 07-23-2008   #2 (permalink)


Vista Home Premium 32bit
 
 

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
Old 07-23-2008   #3 (permalink)
AHartman


 
 

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...
Quote:

>
> 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
Reply

Thread Tools


Similar Threads
Thread Forum
powershell script help - recursive delete based on modified date PowerShell
Deleteing Files in a folder based on date! Vista file management
I want to create a PC based email account Vista mail
Delete files based on last accessed date? PowerShell
Delete based on date PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46