Here is a that organizes files into folders based on their last modified date. Each folder will be named after the last modified date of the files it contains.

@echo off
setlocal enabledelayedexpansion

:: Specify the source folder containing the files
set "sourceFolder=C:\Path\To\Your\Folder"

:: Change to the source folder
cd /d "%sourceFolder%"

:: Loop through all files in the folder
for %%F in (*) do (
    :: Get the creation date of the file using PowerShell
    for /f "delims=" %%A in ('powershell -NoProfile -Command "(Get-Item -LiteralPath '%%F').LastWriteTime.ToString('yyyy.MM.dd')"') do (
        set "creationDate=%%A"
    )
    
    :: Create a folder named after the creation date if it doesn't exist
    if not exist "%sourceFolder%\!creationDate!" (
        mkdir "%sourceFolder%\!creationDate!"
    )
    
    :: Move the file into the corresponding folder
    move "%%F" "%sourceFolder%\!creationDate!\"
)

echo Files organized by creation date.
pause

Instructions

  • Save the script: Copy and paste the above code into a text file and save it with a .bat extension, e.g., OrganizeFilesByDate.bat.
  • Edit the source folder path: Replace C:\Path\To\Your\Folder with the actual path to your folder containing the files.
  • Run the script: Double-click on the .bat file or run it through Command Prompt.

How It Works

  • The script uses PowerShell to extract each file’s last modified date in yyyy.MM.dd format.
  • It creates a folder for each unique date if it doesn’t already exist.
  • Files are moved into their respective folders based on their last modified dates.
  • This script should work on Windows 10 and later versions. Make sure PowerShell is installed and enabled on your .

Key Explanations

Proper Quotation:

  • File paths and filenames are enclosed in double quotes (“) to handle spaces or special characters in file or folder names.

PowerShell Command:

  • The powershell command uses -LiteralPath to avoid issues with special characters in filenames.
  • The creation date format is explicitly set to yyyy.MM.dd for consistency.

Delayed Variable Expansion:

  • Enabled with setlocal enabledelayedexpansion to handle variables like !creationDate! inside loops without conflicts.

PowerShell can extract several date-related properties from files, which include:

  • Creation Time:
    • Represents the date and time when the file was created.
    • Command: (Get-Item “PathToFile”).CreationTime.
  • Last Modified Time:
    • Represents the date and time the file was last written to or modified.
    • Command: (Get-Item “PathToFile”).LastWriteTime.
  • Last Accessed Time:
    • Represents the date and time the file was last accessed (read or opened).
    • Command: (Get-Item “PathToFile”).LastAccessTime.


UPDATE

The previous script is slow & CPU‑hungry. powershell.exe is started once for every single file just to read its timestamp. Spinning up a PowerShell host hundreds or thousands of times dominates the run‑time and keeps the CPU busy even though the actual work is trivial.

Below is a drop‑in replacement that does the same job but launches PowerShell only a single time, returns a list FileName|yyyy.MM.dd to the batch file, and then moves the files.

@echo off
setlocal enabledelayedexpansion

rem --- CONFIG -----------------------------------------------------------------
set "sourceFolder=D:\FILES"
rem ---------------------------------------------------------------------------

pushd "%sourceFolder%"

rem Grab “Name|yyyy.MM.dd” for every file in one PowerShell call
for /f "usebackq tokens=1,2 delims=|" %%A in ( `
  powershell -NoProfile -Command ^
    "Get-ChildItem -File -Name | ForEach-Object { '{0}|{1}' -f $_,(Get-Item $_).LastWriteTime.ToString('yyyy.MM.dd') }"
`) do (

    set "fileName=%%A"
    set "creationDate=%%B"

    if not exist "!creationDate!\" mkdir "!creationDate!"
    move /y "!fileName!" "!creationDate!\"
)

popd
echo Done.
pause


5 Mei 27 Mei 28 April 2021 2022 2023 2024 2025 2026 April 2023 Dokumen Dokumen Kinerja Dokumen Perencanaan Februari 2024 Februari 2025 Inspektorat Daerah Januari 2024 Kecamatan Kementerian Dalam Negeri Kinerja Laporan Hasil Evaluasi Laporan Hasil Evaluasi AKIP Laporan Hasil Evaluasi AKIP Tahun 2022 Laporan Hasil Evaluasi AKIP Tahun 2023 Laporan Hasil Evaluasi AKIP Tahun 2024 Maret 2025 Mei 2024 Mei 2025 Music Music Album Musrenbang Musrenbang Kecamatan Musrenbang RKPD Musrenbang RKPD Tahun 2025 Peraturan Bupati Pirate Rencana Kerja Pemerintah Daerah Rencana Pembangunan Jangka Menengah Daerah RKPD Tahun 2025 RKPD Tahun 2026 RPJMD Tahun 2025-2029 SAKIP SAKIP Tahun 2024 Sekretariat Daerah Surat Edaran

“They’re not gonna catch us. We’re on a mission from God.”

Elwood Blues, The Blues Brothers (1980)

“No one ever wins a fight”

– Elwood Dalton, Road House (2024)

“¿Quiere usted bailar conmigo?”

– Fairuz Hussein – Nights in Barcelona (1989)

“Sate, 200 tusuk makan di sini.”

– Sundel Bolong, Sundel Bolong (1981)

“There’s no place like home.”

– Dorothy Gale, The Wizard of Oz (1939)

“Say ‘hello’ to my little friend!”

– Toni Montana, Scarface (1983)

“I love the smell of napalm in the morning.”

– Lieutenant Colonel Bill Kilgore, Apocalypse Now (1979)

“I’m gonna make him an offer he can’t refuse.”

– Vito Corleone, The Godfather (1972)

“You talkin’ to me?”

– Travis Bickle, Taxi Driver (1976)

TINGGALKAN KOMENTAR

Silakan masukkan komentar anda!
Silakan masukkan nama Anda di sini