neuronyx Posted January 30, 2014 Share Posted January 30, 2014 (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 January 30, 2014 by neuronyx Link to comment Share on other sites More sharing options...
somdcomputerguy Posted January 30, 2014 Share Posted January 30, 2014 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. Link to comment Share on other sites More sharing options...
AutID Posted January 31, 2014 Share Posted January 31, 2014 (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 January 31, 2014 by AutID https://iblockify.wordpress.com/ Link to comment Share on other sites More sharing options...
michaelslamet Posted January 31, 2014 Share Posted January 31, 2014 Or copy the settings.sol to @TempDir first, FileDelete(*.*) on that folder and copy back the settings.sol to the folder Link to comment Share on other sites More sharing options...
neuronyx Posted January 31, 2014 Author Share Posted January 31, 2014 (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 January 31, 2014 by neuronyx Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now