Jump to content
Sign in to follow this  

Deleting ONLY the contents of a directory ...

Recommended Posts


... but not the directory itself ...

DirRemove does exactly what I need to do, except that it also deletes the parent directory, and there is no option to leave the parent.

Why is this a problem?

Take a directory that has specific permissions set on it. The contents need to be deleted, but if the parent directory is deleted, then recreated under my program's user context, then the original permissions are lost.

What are my options? To enumerate the subs of the directory, and delete them individually?

Share this post

Link to post
Share on other sites

use FileDelete


Share this post

Link to post
Share on other sites

May This Help U out

$Folder=FileSelectFolder('Folder Whose Content To Be Deleted','')
While True
If @error Then ExitLoop
If @extended Then

Thumbs Up If Helped

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post

Link to post
Share on other sites

Hi, SlowCoder74. This is what I use to delete all files and subfolders from a user's Temp directory. You may be able to modify it for your needs.

#include <File.au3>
#include <Array.au3>
$_dir1 = _FileListToArray(@TempDir, "*", 2)

If IsArray($_dir1) Then
    For $n = 1 To $_dir1[0]
        $sPath = @TempDir & "" & $_dir1[$n]
        If FileExists($sPath & "") Then
            DirRemove($sPath, 1)

$_dir2 = _FileListToArray(@TempDir, "*", 1)
If IsArray($_dir2) Then
    For $n = 1 To $_dir2[0]
        $sPath = "C:Temp" & $_dir2[$n]
        If FileExists($sPath) Then
Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.