Page 1 of 1

cluster files in folders by its modified date

Posted: 28 Jan 2025 16:42
by threedot
How can I move files in folders by its modified date?

Re: cluster files in folders by its modified date

Posted: 28 Jan 2025 21:37
by phred
Drag and drop?

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

Posted: 28 Jan 2025 22:26
by highend
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;
    }

Re: cluster files in folders by its modified date

Posted: 29 Jan 2025 13:45
by threedot
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.
phred wrote: 28 Jan 2025 21:37 Drag and drop?

Perhaps I'm missing something, but why would this be different than moving any file(s)?
There are several thousand files and can take several days in manual operation.
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;
    }
Thank you! I will try it on next phase. I managed it using powershell script currently like below.

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