Avatar of Michael O'Hara
Michael O'Hara
 asked on

Have Pshell That Creates Directories By Date, But...

It's doing by the file "creation date" - which is not what I am looking for.   Would like to have file last updated timestamp used (i.e. when it was downloaded, not when file was created).

In this case I'd like all files (which are dropped into directory on March 7, 2017) to be copied to a destination directory with only one directory year/month/date of 2017/03/07.   With files that were "created" it's giving me folders with 2013, 2014, 2015, etc.

What is the Powershell function that would pull file download date vs. created date?
function doTheSort([string]$SourceDir, [string]$DestinationDir) {
    $files = get-childitem $SourceDir -Include @("*.txt","*.log", "*.gtm", "*.x340", "p*") 
    $files = get-childitem $SourceDir-Exclude @("Archive","BAI Files","ICMS Output","restore","TEST-ARCH")

    foreach ($file in $files)
    {
        $Directory = $DestinationDir + "" + $file.CreationTime.Date.ToString('yyyy') + "\" + $file.CreationTime.Date.ToString('MM-MMM') + "\" + $file.CreationTime.Date.ToString('dd')

        if (!(Test-Path $Directory))
        {
            New-Item $directory -type directory
        }
        Copy-Item $file.fullname $Directory 
    }
}

doTheSort "I:\Prior Day files for Upload" "C:\DIR-TEST\"

Open in new window

Powershell

Avatar of undefined
Last Comment
Qlemo

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Qlemo

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy