Jump to content
Sign in to follow this  
kushelduv

FileDelete() won't work on multiple drives

Recommended Posts

kushelduv

Maybe my search skills suck but I can't find anything similar to this issue.

I'm trying to write up a small gui program that will create a list of checkboxes with the drive letters and labels of all attached removable media, like flash drives. Then I can select the ones I want and click a button to erase all the data on them.

Everything is working ok, except for FileDelete() to remove the files.

This is the function I have:

Func WipeDrive($driveArray, $driveChecklist)
    For $i = 1 to $driveArray[0] Step 1
        If GUICtrlRead($driveChecklist[$i][$chkbox]) = $GUI_CHECKED Then

            FileDelete($driveArray[$i] & "\*.*")

        EndIf
    Next
EndFunc

Basically I'm passing FileDelete the directory to the selected drive with a wildcard so that all files/folders are deleted.

I've got four drives attached to test this with and this is what's weird.

It works perfectly fine on the first drive, but none of the others.

Program doesn't crash or anything and it behaves as if it is doing it but the files are still there.

I've tried this on three computers, two Win 8 and one Win 7. Same behaviour.

I reformatted all the drives and dumped a couple text files on each.

Still though, only $driveArray[1] will erase, none of the others will.

Am I doing something wrong? Or is there just something really screwed up with my setup?

I am able to delete the files through Explorer with no issues, so I don't think there's any permissions problems.

And I have the program flagged with #requireadmin anyway just to make sure

Can anyone help?

Edited by kushelduv

Share this post


Link to post
Share on other sites
BrewManNH

Why are you wasting time deleting the files when a "Format <drive letter>: /Q" will do the same thing and in far less time?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
NewPlaza

 

Why are you wasting time deleting the files when a "Format <drive letter>: /Q" will do the same thing and in far less time?

 

I second that. This would be far better imo. you could even change the format type such as fat,fat32,ntfs, ect...

Share this post


Link to post
Share on other sites
BrewManNH

As a reason why, it probably has something to do with the root folder of drives being protected in Win7/8 and you'll find working in the root folder on those OSs is never easy. Although unless they're hard drives, these folders shouldn't be protected on an external drive.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
kushelduv

So I just tried

Msgbox(0, "Debug", "Start")

RunWait("Format " & $driveArray[$i] & " /Q")

MsgBox(0, "Debug", "End")

I get the start and end messages, but no formatting ever takes place.

Or do I just not understand what you're saying?

Edited by kushelduv

Share this post


Link to post
Share on other sites
kushelduv

As a reason why, it probably has something to do with the root folder of drives being protected in Win7/8 and you'll find working in the root folder on those OSs is never easy. Although unless they're hard drives, these folders shouldn't be protected on an external drive.

 

Actually, I can delete files in the C: root with no problem, it's only removables beyond the first one that are giving me an issue.

Share this post


Link to post
Share on other sites
kushelduv

So I tried

RunWait(@Comspec & " /c " & "Format " & $driveArray[$]" & " /Q /X", "", @SW_MAXIMIZE)

It works, but requires user interaction to hit enter to start, demands a volume label. 

I want this to a click and walk away deal.

Why is this so difficult to do?

Do I just need to format a few drives to figure out what keys need pressed and pass them too?

That seems like a really clunky way of doing this.

Edited by kushelduv

Share this post


Link to post
Share on other sites
TheSaint

Actually, I can delete files in the C: root with no problem, it's only removables beyond the first one that are giving me an issue.

C(?)

Isn't that your main drive?

Where are you running the script from and what is your full purpose?

In case you aren't aware, FileDelete only removes files, so if it is Folders that are giving you an issue, then you need to use DirRemove.

Are you also checking the return values for your drive array?

Use a msgbox to do that.

Likewise with your GuiCtrlRead line for it's variables.

Are they matching up as required?


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites
BrewManNH

So I tried

RunWait(@Comspec & " /c " & "Format " & $driveArray[$]" & " /Q /X", "", @SW_MAXIMIZE)
It works, but requires user interaction to hit enter to start, demands a volume label. 

I want this to a click and walk away deal.

I'd be very surprised it that line even ran. You have the quotes in the wrong place. Try it with an additional parameter for the format command, "/Y", some versions of format allow that parameter and it's not documented.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
kushelduv

Got to late last night so I didn't feel like posting, but I figured it out.

RunWait(@Comspec & " /c " & "format " & $drivearray[$i] & " /Q /X /Y /FS:FAT32 /V:" & GUICtrlRead($driveChecklist[$i][$editbox]), "", @SW_HIDE)

This is what I put in that formatted the drive perfectly, with no interaction.

In case anyone else comes looking for something like this, this is what's going on:

Running a cmdline argument and terminating cmdline once done, (that's the " /c ")

/Q for quick format cuz who wants to wait for a full one

/X forces a discmount of the drive

/Y avoids user prompts.

/FS: sets the file system to format to (should only need this if you want to change it)

/V: sets the volume label

and the @SW_HIDE prevents the cmd window from being visible (good for having it not interfere with whatever else you're working on at the moment.

May not be the best explanation, but it's working perfectly now.

Thanks for being a sounding board while I work out my idiocy over this.

Cheers! (^.^)

Share this post


Link to post
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
Sign in to follow this  

×