Jump to content
Sign in to follow this  
meier3283

Search and delete a file?

Recommended Posts

meier3283

Does anyone have code already built, that will search all user profiles on a Windows system, and delete a certain file? (extend.dat)

I'm new to autoit, and surfing the help file to get some ideas, but it doesn't seem to be as easy as I was hoping, unless I've missed a function somewhere.

Any help is much appreciated,

- David

Share this post


Link to post
Share on other sites
99ojo

Hi,

you are a lucky guy and should play lotto this weekend.

Tested on XP and 2000 for deleting all files in every users temp directory.

Change it for your purpose:

#include <array.au3>
#include <file.au3>
;array holding default prof and service accounts and other excludes you want to, if you don't mind comment it out
$ardefuser [4] = ["All Users", "Default User", "LocalService", "NetworkService"]
;get variable SystemDrive
$sysdrive = EnvGet ("SystemDrive")
;get default profile folder
; if you have 64 Bit OS see helpfile RegRead to change code....
$profdir = StringReplace (RegRead ("HKLM\Software\Microsoft\Windows NT\CurrentVersion\ProfileList", "ProfilesDirectory"), _
"%SystemDrive%", $sysdrive)
;get folders in Document and Settings and store in array
$arfolders = _FileListToArray ($profdir, "*", 2)
;Loop over array
For $i = 1 To UBound ($arfolders) - 1
    ;if folder not found in default prof and service array then delete all in Temp Folder
    ;see remarks above if you don't mind, change line to
    ;FileDelete ($profdir & "\" & $arfolders [$i] & "\Local Settings\Temp\*.*")
    If _ArraySearch ($ardefuser, $arfolders [$i]) = - 1 Then FileDelete ($profdir & "\" & $arfolders [$i] & "\Local Settings\Temp\*.*")
Next

A clever search on forum: "delete file user" could have shorten your waiting time -> Code on 5 th position on search page. :mellow:

;-))

Stefan

Edited by 99ojo

Share this post


Link to post
Share on other sites
kaotkbliss

A clever search on forum: "delete file user" could have shorten your waiting time -> Code on 5 th position on search page. :mellow:

;-))

Stefan

Heh Heh, I know of at least a few times I would have liked to been able to "delete user"... :(


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites
meier3283

Hi,

you are a lucky guy and should play lotto this weekend.

Tested on XP and 2000 for deleting all files in every users temp directory.

Change it for your purpose:

#include <array.au3>
#include <file.au3>
;array holding default prof and service accounts and other excludes you want to, if you don't mind comment it out
$ardefuser [4] = ["All Users", "Default User", "LocalService", "NetworkService"]
;get variable SystemDrive
$sysdrive = EnvGet ("SystemDrive")
;get default profile folder
; if you have 64 Bit OS see helpfile RegRead to change code....
$profdir = StringReplace (RegRead ("HKLM\Software\Microsoft\Windows NT\CurrentVersion\ProfileList", "ProfilesDirectory"), _
"%SystemDrive%", $sysdrive)
;get folders in Document and Settings and store in array
$arfolders = _FileListToArray ($profdir, "*", 2)
;Loop over array
For $i = 1 To UBound ($arfolders) - 1
    ;if folder not found in default prof and service array then delete all in Temp Folder
    ;see remarks above if you don't mind, change line to
    ;FileDelete ($profdir & "\" & $arfolders [$i] & "\Local Settings\Temp\*.*")
    If _ArraySearch ($ardefuser, $arfolders [$i]) = - 1 Then FileDelete ($profdir & "\" & $arfolders [$i] & "\Local Settings\Temp\*.*")
Next

A clever search on forum: "delete file user" could have shorten your waiting time -> Code on 5 th position on search page. :mellow:

;-))

Stefan

Thanks Stefan, I've always bragged, in the past, about being able to get anything out of google, however, the search on this forum wasn't giving it up without a fight. I searched high and low, without finding anything, prior to posted. ( I too hate people that don't help themselves ) I'll try harder next time. And thank you very much for your code, I'll put it to good use.

- David

Share this post


Link to post
Share on other sites
99ojo

Hi,

you are welcome.

( I too hate people that don't help themselves ) I'll try harder next time.

Never mind; I posted code :(

I'll put it to good use.

Hopefully :mellow:

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.