powershell - 从 FTP 服务器中提取文件不会根据文件日期创建目录
问题描述
我有一个能够通过 FTP 连接的脚本,能够提取文件,但不能根据文件修改日期创建目录/目标是将所有这些文件放入一个目录中,因为该脚本将每天运行。我尝试通过以下参数:
param(
[string]$date =[datetime]((Get-Date).AddDays(-4)).ToString(“MM\dd\yyyy"),
[string]$FilesToExcludeArray = @(""),
[string]$FilesToIncludeArray = @("*.*"),
[string]$remotepath ="/inbox/"
[string]$localpath="c:\test\APRIL\$date\"
)
我不会发布完整的脚本,但这是 $date 之后调用的地方
# Select the most recent files
$latest = $directory.Files |
Where-Object {$_.LastWriteTime -ge $date -and -Not $_.IsDirectory -and $_.Name -notlike
$FilesToExcludeArray -and $_.Name -like $FilesToIncludeArray}| Select-Object
$download = $False
我很感激任何帮助
解决方案
您应该以正确的格式制作 Lastwritetime:
$latest = $directory.Files | Where-Object {$_.LastWriteTime.ToString("MM\dd\yyyy") -ge $date -and -Not $_.IsDirectory -and $_.Name -notlike $FilesToExcludeArray -and $_.Name -like $FilesToIncludeArray}
$download = $False
推荐阅读
- c++ - 模板功能图
- laravel - 未找到存储数据 RESTfull API 404
- reactjs - React JS 多个提交按钮 react-hook-form
- python - 如何在python中将不同年份之间的距离分成12个相等的部分
- python - 通过 Google Docs API Python 客户端库创建新的 Google 文档的命令是什么?
- angular - 从 Api 服务调用角度选择默认下拉列表
- c++ - 编译器找不到 std::variant 声明
- python - python 元组以逗号结尾
- php - 在 Laravel 8 中将图表刀片视图转换为 pdf
- c# - c#和XPath,需要帮助提取2段文本