我一直非常成功地使用它,直到有人弄乱了该文件。
所以我需要隐藏该文件或将其移动到隐藏文件夹。我遇到的问题是它在它所在的目录中创建了新文件夹。
我希望它在父目录中创建新文件夹。
###Get the year entered by the user
$year = Read-Host "Please enter year"
$nextyear = [int]$year + 1
$yearfolder = "$year-$nextyear"
###Set the starting date
$startdate = [DateTime] "01 April $($year)"
$count = 1
###Set the file's path by combining the folder path and the filename
$filename = join-Path -Path (Get-location) -ChildPath "a.txt"
###Create folder based on the year entered by the user
New-Item -ItemType Directory -Name "$($yearfolder)"
###Change directory to the newly created folder
cd "$($yearfolder)"
While ( $count -lt 13)
{
###Create folders
$newfolder = "$($count.ToString('00')) - $($startdate.ToString('MMMM yyyy'))"
New-Item -ItemType Directory -Name "$newfolder"
#Copy file to new folder
Copy-Item -Path $filename -Destination $newfolder
#Add one month
$startdate = $startdate.AddMonths(1)
#Increment the counter
$count = $count + 1
}