cluster files in folders by its modified date

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
threedot
Posts: 20
Joined: 11 Oct 2010 15:17

cluster files in folders by its modified date

Post by threedot »

How can I move files in folders by its modified date?

phred
Posts: 561
Joined: 26 Dec 2021 02:10
Location: XY 64bit on Windows 10 at 100% from Boston USA

Re: cluster files in folders by its modified date

Post by phred »

Drag and drop?

Perhaps I'm missing something, but why would this be different than moving any file(s)?

highend
Posts: 14571
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: cluster files in folders by its modified date

Post 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;
    }
One of my scripts helped you out? Please donate via Paypal

threedot
Posts: 20
Joined: 11 Oct 2010 15:17

Re: cluster files in folders by its modified date

Post 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

Post Reply