首页 > 解决方案 > 从 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

我很感激任何帮助

标签: powershell

解决方案


您应该以正确的格式制作 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

推荐阅读