cluster files in folders by its modified date
cluster files in folders by its modified date
How can I move files in folders by its modified date?
Re: cluster files in folders by its modified date
Drag and drop?
Perhaps I'm missing something, but why would this be different than moving any file(s)?
Perhaps I'm missing something, but why would this be different than moving any file(s)?
Re: cluster files in folders by its modified date
Via scripting?
Code: Select all
setting "BackgroundFileOps", 0;
foreach($file, <get SelectedItemsPathNames>, <crlf>, "e") {
$dst = gpc($file, "path") . "\" . formatdate(property("#date.m", $file), "yyyy-mm-dd");
moveto $dst, $file, , 2, 2;
}
One of my scripts helped you out? Please donate via Paypal
Re: cluster files in folders by its modified date
I consider to use move to option by "log<datec yyyy-mm-dd>" but it doesn't works like I expected. It don't use each file's modified date, just use first selected file's date modified for entire selected files.
There are several thousand files and can take several days in manual operation.
Thank you! I will try it on next phase. I managed it using powershell script currently like below.highend wrote: ↑28 Jan 2025 22:26 Via scripting?Code: Select all
setting "BackgroundFileOps", 0; foreach($file, <get SelectedItemsPathNames>, <crlf>, "e") { $dst = gpc($file, "path") . "\" . formatdate(property("#date.m", $file), "yyyy-mm-dd"); moveto $dst, $file, , 2, 2; }
Code: Select all
# PowerShell Script to Organize .log Files by Modified Date
param (
[Parameter(Mandatory = $true)]
[string]$FolderPath
)
# Check if the folder exists
if (-not (Test-Path -Path $FolderPath)) {
Write-Host "The specified folder does not exist. Exiting..." -ForegroundColor Red
exit
}
# Get all .log files in the folder
$logFiles = Get-ChildItem -Path $FolderPath -Filter *.log -File
if ($logFiles.Count -eq 0) {
Write-Host "No .log files found in the specified folder." -ForegroundColor Yellow
exit
}
# Process each .log file
foreach ($file in $logFiles) {
# Get the last modified date of the file
$modifiedDate = $file.LastWriteTime.ToString("\log_yyyy-MM-dd")
# Create a folder with the modified date if it doesn't exist
$dateFolder = Join-Path -Path $FolderPath -ChildPath $modifiedDate
if (-not (Test-Path -Path $dateFolder)) {
New-Item -Path $dateFolder -ItemType Directory | Out-Null
}
# Move the file to the corresponding folder
$destinationPath = Join-Path -Path $dateFolder -ChildPath $file.Name
Move-Item -Path $file.FullName -Destination $destinationPath -Force
Write-Host "Moved '$($file.Name)' to '$($dateFolder)'" -ForegroundColor Green
}
Write-Host "Files successfully organized by modified date." -ForegroundColor Cyan
XYplorer Beta Club