Sign in to follow this  
Followers 0
neuronyx

Delete all files in a directory but one

5 posts in this topic

#1 ·  Posted (edited)

Hi All-

I am trying to script deleting all files in a folder but one. I am doing this for the adobe flash folder in C:UsersUSERAppDataRoamingMacromediaFlash Playermacromedia.comsupportflashplayersys

I need to delete everything but the settings.sol folder under the sys folder. There are multiple other subfolders, each containing their own settings.sol file that I DO want deleted.

Is there a simple way to script autoIT so it ignores the root settings.sol file but deletes everything else.

Here is what I have but no luck so far:

#include <File.au3>

$macromediaDIR = @AppDataDir & '\Roaming\Macromedia\Flash Player\macromedia.com\support\flashplayer\sys\'
$mDirArray = _FileListToArray($macromediaDIR, "settings.sol", 1)

For $i = 1 To UBound($mDirArray)
    MsgBox(0,"",$mDirArray[$i])
Next

I only have msgbox so I can see what the command will be deleting, I will replace this with filedelete later on.

Thanks in advance to any replies!

Edited by neuronyx

Share this post


Link to post
Share on other sites



See the two FileFind functions and the FileDelete function in the Help file. If the filename found doesn't equal the file you specify, delete it. That's how I would do it anyway. I'm sure there are other ways too.


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Maybe something like this?

#include <File.au3>
$macromediaDIR = @AppDataDir & '\Roaming\Macromedia\Flash Player\macromedia.com\support\flashplayer\sys\'
$settings = $macromediaDIR & "settings.sol"
$mDirArray = _FileListToArray($macromediaDIR, "*", Default, True)
For $i = 1 To UBound($mDirArray)
    If $mDirArray[$i] <> $settings Then FileDelete($mDirArray[$i])
Next

However I can't test it because I need my files ;)

Edited by AutID

Share this post


Link to post
Share on other sites

Or copy the settings.sol to @TempDir first, FileDelete(*.*) on that folder and copy back the settings.sol to the folder

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

All are great solutions! I must have been exhausted by the end of yesterday since I couldn't think of a single one of these. Thanks all!

To AutID- I tried your solution however nothing gets deleted. I do not see any error however when trying to run the code. Any ideas why this may be the case?

EDIT: Found it:

#include <File.au3>
$macromediaDIR = @AppDataDir & '\Macromedia\Flash Player\macromedia.com\support\flashplayer\sys\'
$settings = $macromediaDIR & "settings.sol"
$mDirArray = _FileListToArray($macromediaDIR, "*", Default, True)
For $i = 1 To UBound($mDirArray)
    If $mDirArray[$i] <> $settings Then FileDelete($mDirArray[$i])
Next

I had Roaming twice in the path so it couldn't be found. All set!

Edited by neuronyx

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