Jump to content

Delete files and folders from a drive.


Belini
 Share

Recommended Posts

This script is especially useful to delete those annoying files that comes in USB stick, use with care not to accidentally delete important files of some important unit

#include <File.au3>
#include <Array.au3>
#include <String.au3>

; ======================================================
; AutoIt3 V 3.3.9.4
; Author: Belini
; Date: 07.26.2012
; Goal: Delete all the folders and files from one drive.
; Note: Use carefully at your own risk.
; ======================================================

delete_all()
Func delete_all()
Local $list, $counter = 0

$path = FileSelectFolder("Enter the path of unity", "")
If StringLen($path) > 3 Then $path = StringMid($path, 1, 3)
$list = _FileListToArray($path)
$contar = UBound($list)
$contar = $contar - 1

If $contar > 0 Then
_ArrayDisplay($list, "Please note these items will be deleted!")
$option = MsgBox(1, "delete files", "All files are deleted, or even delete?")

If $option = 2 Then
MsgBox(4096, "Canceled", "The operation was canceled", 3)
Exit
EndIf

If $option = 1 Then
While 1
$counter += 1
If FileExists($path & $list[$counter]) And FileGetAttrib($path & $list[$counter]) = "D" Then DirRemove($path & $list[$counter], 1)
If FileExists($path & $list[$counter]) And FileGetAttrib($path & $list[$counter]) = "A" Then FileDelete($path & $list[$counter])
If $counter >= $contar Then ExitLoop
Sleep(1)
WEnd
EndIf
MsgBox(4096, "Files deleted successfully!", "All files on drive " & $path & " was deleted.")
Else
MsgBox(4096, "No files to delete", "There is no file to be deleted in this unit!")
EndIf

EndFunc ;==>delete_all
Edited by Belini
Link to comment
Share on other sites

  • Moderators

Out of curiosity, why this line?

if StringLen($caminho) > 3 then $caminho = StringMid($caminho, 1, 3)

If, for example, I am trying to delete files in C:Temp, the line above moves the directory up to C:. That could make it a bad day :)

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

If you choose a folder on drive eg E: test, using stringmid + stringlen the result is the same E: why the purpose of this script is to clean the entire unit.

Link to comment
Share on other sites

Link to comment
Share on other sites

Link to comment
Share on other sites

@Belni

This is the MS-DOS commands, be aware that this code snippet: Runwait (@ ComSpec & "/ c" & ... - serves so you can run programs including MS-DOS commands!

Type in a DOS window: Format /?

You will see an explanation of the command!

Regards,

João Carlos.

Edited by JScript

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...