Menghapus file secara otomatis berdasarkan tanggal di Windows

Dapat request nh dari programmer kantor, ia ingin filenya yang berada di Server dihapus tiap bulan berdasarkan tanggal Server. Setelah searching akhirny ketemu juga, namanya Forfiles. Forfiles hanya terdapat di Windows 2003, Win Vista , Win 7.

Untuk lebih detail tau tentang syntak Forfiles, ketikkan Forfiles /? maka akan menampilkan

Parameter Description

/p Specifies the path from which to start the search. By default, searching starts in the current working
directory.

/m Searches files according to the specified search mask. The default search mask is *.*.

/s Instructs the forfiles command to search into subdirectories recursively.

/c “” Runs the specified command on each file. Command strings should be enclosed in quotation marks. The default
command is “cmd /c echo @file”.

/d [{+|-}][{|}] Selects files with a last modified date within the specified time frame.

Selects files with a last modified date later than or equal to (+) or earlier than or equal to (-) the
specified date, where Date is in the format MM/DD/YYYY.
Selects files with a last modified date later than or equal to (+) the current date plus the number of days
specified, or earlier than or equal to (-) the current date minus the number of days specified.
Valid values for Days include any number in the range 0–32,768. If no sign is specified, + is used by default.

/? Displays help at the command prompt.

Syntaks untuk menghapus file perbulan adalah

Forfiles -pC:\backup /S /M *.* /D -30 /C “cmd /C del /q @path”

Syntaks ini akan menghapus file di C:\backup akan terhapus kurang dari 30 hari. Sebelumny jalankan syntaks dibawah ini untuk mengetahui file apa saja yang akan dihapus :

Forfiles -pC:\backup /S /M *.* /D -30 /C “cmd /C Echo 0x22@Path\@File0x22”

Syntaks tersebut akan menampilkan file yang akan dihapus.

Agar dapat terhapus otomatis tinggal di buatkan Schedule Task di Windows..Maka jrennggg, selesai

Iklan

3 thoughts on “Menghapus file secara otomatis berdasarkan tanggal di Windows

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s