简体   繁体   中英

Move file to newly created subfolder

I have to move a file daily to a folder which is a month folder. When the new months comes than the script should identify the newly create folder (which I will create with different script) and start pushing files to that new folder. Now when the year changes the script should identify the folder with the new year and under that the subfolder for the month and push the file to that new subfolder.

Sorry if this sounds confusing. Need help I know how to move files to another folder using PowerShell but getting into that hierarchy is something I am not able to accomplish.

try Something like this :

$CurrentDate=get-date
$year, $month= $CurrentDate.Year, $CurrentDate.Month
$storagedir="c:\temp\$year\$month"

if (! (Test-Path $storagedir))
{
    New-Item -ItemType Directory $storagedir
}

Move-Item "C:\temp\dbhash.csv" $storagedir -Force

Never Mind Got it. Below is the final script that worked perfectly for me

$CurrentDate=get-date
$year = $CurrentDate.Year
$folderName = (Get-Date).tostring("dd-MM-yyyy-hh") 
$storagedir="C:\Users\$year\$folderName"
if (! (Test-Path $storagedir))
{
    New-Item -ItemType Directory $storagedir
    }
if (Test-Path $storagedir)
{

Move-Item "C:\Users" $storagedir -Force
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM