-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmove-files-over-5mb.ps1
More file actions
36 lines (29 loc) · 1.28 KB
/
Copy pathmove-files-over-5mb.ps1
File metadata and controls
36 lines (29 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Set main directory and threshold
$sourceFolder = "C:\Users\FaullS\.aws\s3Downloads"
$targetRoot = Join-Path $sourceFolder "FilesOver5MB"
$sizeThresholdMB = 4.9
$sizeThresholdBytes = $sizeThresholdMB * 1MB
# Create target root folder if it doesn't exist
if (-not (Test-Path $targetRoot)) {
New-Item -ItemType Directory -Path $targetRoot -Force | Out-Null
}
# Get all files under source folder recursively
$allFiles = Get-ChildItem -Path $sourceFolder -Recurse -File
foreach ($file in $allFiles) {
# Skip already moved files inside FilesOver5MB
if ($file.FullName -like "$targetRoot*") { continue }
if ($file.Length -gt $sizeThresholdBytes) {
# Compute relative path from source root
$relativePath = $file.FullName.Substring($sourceFolder.Length + 1)
# Build new target path preserving subfolders
$targetPath = Join-Path $targetRoot $relativePath
$targetDir = Split-Path $targetPath
# Create target directory if needed
if (-not (Test-Path $targetDir)) {
New-Item -ItemType Directory -Path $targetDir -Force | Out-Null
}
# Move the file
Write-Host "Moving $($file.FullName) to $targetPath"
Move-Item -Path $file.FullName -Destination $targetPath
}
}