Sign in to follow this  
Followers 0
Garrett19212

Delete all files/folders in a folder.

24 posts in this topic

How can I delete all the folders and files in a folder, without deleteing the folder itself.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

How can I delete all the folders and files in a folder, without deleteing the folder itself.

hmm... DirRemove() ? ;)

$dir = 'c:\bat\junk'
DirRemove($dir,1)
DirCreate($dir)

If you need to save the info about the dir (creation time, etc.) , grab and store the necessary info and modify

the values after you recreate the dir.

Edited by flyingboz

Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Share this post


Link to post
Share on other sites

Yes, I have tried that but thats where the problem is. I can't delete the folder. Since im cleaning the history, cookies etc, and when you try to delete the folder, windows denies it.

Share this post


Link to post
Share on other sites

Yes, I have tried that but thats where the problem is. I can't delete the folder. Since im cleaning the history, cookies etc, and when you try to delete the folder, windows denies it.

You have a file permissions and/or filehandle issue, not an autoit issue.

Does rd work?

I bet you just have to close your browser before deleting the directory, and possibly change an attribute on the directory.

If that doesn't work, get a filehandle utility and look at the directory attributes to determine what the problem is and resolve it before attempting the deletion.


Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Share this post


Link to post
Share on other sites

The error windows gives me is.

Cookies is a Windows system folder and is required for Windows to run properly. It cannot be deleted.

Share this post


Link to post
Share on other sites

Yes, I have tried that but thats where the problem is. I can't delete the folder. Since im cleaning the history, cookies etc, and when you try to delete the folder, windows denies it.

You cannot delete a folder if an application is still using the folder (has an open filehandle). That's a restriction and security measure of windows. You might ask: What can I do? Well, not much.... Check out this: http://www.michna.com/kb/WxCannotDelete.htm

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

He posted same time as me so, incase you missed it.

The error windows gives me is.

Cookies is a Windows system folder and is required for Windows to run properly. It cannot be deleted.

Share this post


Link to post
Share on other sites

The error windows gives me is.

Cookies is a Windows system folder and is required for Windows to run properly. It cannot be deleted.

I would think that the error message is clear enough. If you've deleted the files, what do you care about the empty directory? It will just be created again the next time IE opens.

Of course, if you're trying to hide your tracks, you're barking up the wrong tree entirely - anybody who knows what they're doing can still find out you've been where you ain't supposed to be, even if you blow all that away.


Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Share this post


Link to post
Share on other sites

Of course, if you're trying to hide your tracks, you're barking up the wrong tree entirely - anybody who knows what they're doing can still find out you've been where you ain't supposed to be, even if you blow all that away.

No i'm not trying to hide my tracks.

But is there anyway to get all of the files in a folder, and then use FileDelete on them?

Share this post


Link to post
Share on other sites

why not DOS it up

_RunDOS("del /Q C:\*.*")

skippidy doo


[right][font="Courier New"]...Run these streets all day, I can sleep when I die.[/font] [/right]

Share this post


Link to post
Share on other sites

Is there anyway I can find the files inside of the folder?

Share this post


Link to post
Share on other sites

Is there anyway I can find the files inside of the folder?

u mean as its delteing it? or look at the files and delete certain 1s?


[right][font="Courier New"]...Run these streets all day, I can sleep when I die.[/font] [/right]

Share this post


Link to post
Share on other sites

I mean by, get all the file paths inside of the folder, and use FileDelete on them. So I can avoid deleteing the folder.

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

I mean by, get all the file paths inside of the folder, and use FileDelete on them. So I can avoid deleteing the folder.

Hm... Let's read the help file....

FileDelete

--------------------------------------------------------------------------------

Delete one or more files.

FileDelete ( "path" )

Parameters

Path The path of the file(s) to delete. Wildcards are supported

Example

FileDelete("D:\*.tmp")

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

How can I detect the sub folders in it, since I don't think folders are a file type...

Share this post


Link to post
Share on other sites

How can I detect the sub folders in it, since I don't think folders are a file type...

We have.

C:\k1\k2

C:\k1\k3

C:\k1\k3\k4

DirRemove("C:\k1\.",1) will remove everything below C:\k1 AND also C:\k1 !! See help file.

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

Sigh you still don't understand.

I don't want to remove the folders.

Share this post


Link to post
Share on other sites

Sigh you still don't understand.

I don't want to remove the folders.

This will do the job, BUT in Beta 80, it seems that stringinstr returns a 1 when false and a 0 when true??? I put 1 in where normally I would use a 0. Check this script out on a folder with JUNK in it!!!

#include <constants.au3>
#include <array.au3>
Global $i
dim $eachline[500]
dim $line = ""
$pid = run(@comspec & ' /c ' & "dir c:\backups /b /s",@tempdir,"",$stdout_child)
While 1
    $line = StdoutRead($pid)
    If @error = -1 Then ExitLoop
$eachline = StringSplit($line,@crlf,1)
    for $i = $eachline[0]-1 to 2 Step -1
        msgbox(4096,"This line",$eachline[$i])
        MsgBox(4096,"FileAttrib=",FileGetAttrib($eachline[$i]))
        if stringinstr(FileGetAttrib($eachline[$i]),"D") = 0 then MsgBox(4096,"File to be deleted is:",$eachline[$i])
    ; FileDelete($eachline[$i]); DANGER!!!! IF YOU UNCOMMENT THIS LINE IT WILL DELETE EVERYTHING IN YOUR TARGET FOLDER!!!!!
    Next        
Wend

...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format

Share this post


Link to post
Share on other sites

I tested it and it seems very buggy, its saying stuff like D, A. But it returns some of the correct file names.

Share this post


Link to post
Share on other sites

I tested it and it seems very buggy, its saying stuff like D, A. But it returns some of the correct file names.

It would be great if you would take the time to understand the code before calling it buggy. It returns a D if it is a directory. If it is not a directory it shows the message "File to be deleted". The rest is up to you. Bye...

...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format

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  
Followers 0