是否有检查文件夹名称是否与当前日期相同的功能?
Is there a function to check if a folder name is the same as current date?
我需要帮助来编写一个 powershell 脚本来检查是否存在与当前日期 (ddmmyyyy) 同名的文件夹。
该脚本每天 运行 并将所有文件从该文件夹复制到另一个覆盖所有内容。
我在 google 中搜索过,但找不到示例
我希望脚本检查当前文件夹的子文件夹和 select 与当前日期同名的文件夹,然后进入该文件夹并将文件复制到另一个位置。
这是一个基本脚本,用于检查当前日期的文件夹是否存在。
$folderPath = "c:\myRootFolder"
$date = Get-Date
$dateString = $date.ToString("yyyyMMdd")
$doesexist = Test-Path ($folderPath + "\" + $dateString)
if($doesexist){
Write-Host "folder does Exist"
}else{
Write-Host "Folder does not exits"
}
#$date = Get-Date
$dateString = Get-Date -Format "yyyyMMdd"
$doesexist = Test-Path ($folderPath + "\" + $dateString)
if($doesexist){
Copy-Item -Force ($folderPath + "\" + $dateString + "\*") -Destination $folderPath
}else{
Write-Host "Folder does not exits"
}```
我需要帮助来编写一个 powershell 脚本来检查是否存在与当前日期 (ddmmyyyy) 同名的文件夹。 该脚本每天 运行 并将所有文件从该文件夹复制到另一个覆盖所有内容。
我在 google 中搜索过,但找不到示例
我希望脚本检查当前文件夹的子文件夹和 select 与当前日期同名的文件夹,然后进入该文件夹并将文件复制到另一个位置。
这是一个基本脚本,用于检查当前日期的文件夹是否存在。
$folderPath = "c:\myRootFolder"
$date = Get-Date
$dateString = $date.ToString("yyyyMMdd")
$doesexist = Test-Path ($folderPath + "\" + $dateString)
if($doesexist){
Write-Host "folder does Exist"
}else{
Write-Host "Folder does not exits"
}
#$date = Get-Date
$dateString = Get-Date -Format "yyyyMMdd"
$doesexist = Test-Path ($folderPath + "\" + $dateString)
if($doesexist){
Copy-Item -Force ($folderPath + "\" + $dateString + "\*") -Destination $folderPath
}else{
Write-Host "Folder does not exits"
}```