amazon-web-services - 如何使用文件夹的最后修改日期将文件上传到 S3?
问题描述
我正在尝试组合一个 PowerShell 脚本,该脚本将允许我根据文件夹的最后修改日期将文件上传到我的 AWS S3 存储桶。
这就是我迄今为止所拥有的:
using namespace System.IO;
Set-AWSCredentials -StoredCredentials MyCredentialsAws
Set-DefaultAWSRegion us-east-1
[String] $root = "C:\Users\Administrator\Documents\TestFolder";
[DateTime]$today = [DateTime]::Now.Date;
[FileSystemInfo[]]$folderList = Get-ChildItem -Path $root -Directory;
foreach( $folder in $folderList ) {
if( $folder.LastWriteTime -lt $today ) {
[String] $folderPath = $folder.FullName;
aws s3 cp $folder s3://bucketname/$folder --recursive
}
}
但是,上面给了我错误:
“用户提供的路径不存在”
任何帮助,将不胜感激。
解决方案
一方面,$folder
当aws
您可能打算使用$folderPath
. 此外,扩展的Get-ChildItem
不一致。根据上下文,对象有时会扩展为名称,有时会扩展为完整路径(有关更详细的说明,请参见此处)。因此,明确使用给定场景所需的属性(Name
, FullName
, ...)被认为是一种很好的做法。
if ($folder.LastWriteTime -lt $today) {
$folderPath = $folder.FullName
$folderName = $folder.Name
aws s3 cp $folderPath s3://bucketname/$folderName --recursive
}
推荐阅读
- c++ - 在 C++ 中更改 OpenCV cv::Mat 类对象的数据指针
- javascript - 检查 HTMLCollection 是否包含具有空值的元素
- powershell - Azure Pipeline:在 Windows 远程计算机上运行 PowerShell 脚本的 SSH 任务
- asp.net-core - 当存在 2 个具有相同名称但具有不同路由前缀的 OData 实体集时,如何正确路由控制器?
- python - SPARQL查询获取父类,然后查找父类与第三类的关系并查找第三类的注释
- excel - 根据 Master sheet 中的 ID 创建新工作表并复制数据
- spring - 使用 ManytoOne 时如何删除行表单实体?
- python - FastAPI、SQLAlchemy、pytest,无法获得 100% 的覆盖率,它没有正确收集
- ios - 是否可以在 react native 中使用 ffplay 预览 ffmpeg 的输出?
- r - 决定 1 或 2 或两者都由 2 个变量分组