Senin, 20 April 2020

SCRIP DEL-windows

Menghapus file dengan ekstensi tertentu secara massal di Windows

Kasusnya kali ini dalam satu folder tidak sengaja tercopy ribuan file JPG dan saya ingin membersihkan isinya karena telah tercampur. Memilih satu per satu walaupun bisa dipilih secara massal memang mudah tapi agak repot saja. Ada resiko salah menghapus file penting lainnya tapi. Untungnya bisa dengan mudah dibedakan berdasarkan ekstensinya. Tapi kalau ada cara yang praktis, cepat dan mudah tentu sebaiknya digunakan bukan?
Alat yang akan kita manfaatkan kali ini hanyalah sebuah command prompt saja. Misal kita ingin menghapus file dengan ekstensi JPG tadi maka perintahnya adalah:
del nama_direktori\*.jpg
Pastikan command prompt sesinya aktif pada lokasi file yang ingin dihapus.
cmd-hapus-file-ekstensi-tertentu
Langsung jalankan saja dan prosesnya akan dimulai. Kalau banyak maka bisa agak lama baru selesai. Kalau muncul pesan Could Not Find setelah mengeksekusinya berarti file – file dengan ekstensi tersebut tidak ditemukan.
Saya ingatkan sebelum menekan ENTER agar selalu memperhatikan apakah lokasi direktorinya sudah tepat dan jenis filenya juga benar. Kalau sampai salah bisa fatal akibatnya dan nanti malah kebingungan ingin memulihkan file – file yang salah terhapus tadi.
Selesai sudah dan semua file yang berlokasi di D:\ pada folder uTekno dengan ekstensi jpg akan dibersihkan tidak bersisa. Selesai. 🙂
Oh ya, perintah ini juga bisa dieksekusi pada PowerShell. Bahkan untuk menggantikan perintah del ada alternatifnya rm karena sama – sama alias dari cmdlet Remove-Item.

Topik terkait:

How to Create Batch to Delete File Automatically – Command Line Explanation

Furthermore in this tutorial we will explain way to create batch to delete file automatically using command line. This is useful if you have limited space on a HDD and need to delete files on some folders that populated automatically. In my case SQL backups folder.
After tutorial where we created batch to zip files, this is other useful tutorial for your daily jobs.
You will need to delete those files manually every day and this is not good practice. On the other hand you can create script to delete file automatically. All of that without installing any Third-party software. In fact this example will show steps for creating batch file and you can use Task Scheduler to run.
Other useful batch tutorial:

Batch to delete file automatically.

Furthermore we will explain two methods:
  • Batch file to delete file based on extension of the file.
  • Script file to delete all files

Batch to delete file based on extension.

In fact Batch files are scripts that can run to perform tasks on you system. They are the best ways to save time. In fact we will delete files on specific folders. For example, we will tell the batch file to delete .txt files that are located in the Test folder.
Create a text file and copy the below command line:
echo Batch to delete file

del "D:\Test_1\Test\*.txt" /s /f /q

echo Done!
Save like a delete.bat. Save anywhere except D:\Test_1\Test\ .
del “D:\Test_1\Test\*.txt”  The basic command locates the folder.
/s parameter will delete all files contained in the directory subfolders. If you do not want to delete files from subfolders, remove /s parameter.
/f parameter ignores any read-only setting.
/q “quiet mode,” meaning you won’t be prompted Yes/No
Batch to delete file
Batch to delete file
Note! Remember to change the directory to match your computer.
Run as Administrator and all files with defined extension will deleted.

Script file to delete all files.

As a result we will tell the Script file to delete all files that are located in the Test folder.
echo deleting file

del "D:\Test_1\Test\*.*" /s /f /q

echo Done!
At this point run as Administrator and all files located in the “Test” folder will deleted.
Batch to delete all files
Batch to delete all files

Also you can use Task Scheduler to create scheduled task.
————————————————————————————–

Tidak ada komentar:

Posting Komentar