Jump to content

_FileListToArray - I want to remove any "temp" directories from the array


Recommended Posts

_FileListToArray - I want to remove any "temp" directories from the array

Hi All,

This is what I have so far and I always drive my self crazy when it comes to arrays so yes, I'm giving up... asking for help lol. Sorry if I'm a newb but I love this program, forum and culture - you guys are the best! Thanks!

Trying to remove any "Temp" directory from the $Filelist array - and I have a whole bunch of others listed in my notes.

For now I'm testing on my D: drive for a temp directory... but I would like to delete any C:\Documents and Settings\ for any user folder not system related. We have devices that everyone logs into and it clusters things up.

#include <Array.au3>
#include <File.au3>

#RequireAdmin

Global $ProgramTitle1, $FileList, $sPath

$ProgramTitle1 = "Test"

SplashTextOn($ProgramTitle1, "Creating file list for D:\", 400, 40, -1, -1, 2, "", 10)
Sleep (2000)

$sPath = "D:\"

$FileList = _FileListToArray($sPath , "*" , 2)
SplashOff()

If @error = 1 Then
MsgBox(0, "", "Path not found or invalid")
Exit
EndIf
If @error = 4 Then
MsgBox(0, "", "No File(s) Found")
Exit
EndIf

_ArrayDisplay($FileList, "Before")

Local $rows = UBound($FileList)
Local $cols = UBound($FileList, 2)
Local $dims = UBound($FileList, 0)

MsgBox(0, "The " & $dims & "-dimensional array has", _
$rows & " rows, " & $cols & " columns")

; Work in progress AKA I have no idea what I'm doing and I'm trying to get it right lol...

For $i = 1 To $FileList[0]
If $FileList[$i] == "Temp" Then _ArrayDelete($FileList, $i)
Next

_ArrayDisplay($FileList, "After")

;Note to self "Administrator" or "All Users" or "Default User" or "LocalService" or "NetworkService" or @UserName

"Maybe I'm on a road that ain't been paved yet. And maybe I see a sign that ain't been made yet"
Song Title: I guess you could say
Artist: Middle Class Rut

Link to comment
Share on other sites

  • Moderators

souldjer777,

Take a look at the RecFileListToArray UDF in my sig - that allows you to define folder names that are not listed in the return. ;)

Please ask again if you need more help. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

If you're looking to delete user's folders other than the default ones, such as Administrator/Default User/All Users (xp and below), then you might want to take a look at the link in my signature for how I gathered the user folders in a script I posted that I use to back up user's folders. This script should work on XP or above, and you can modify it as needed to do what you're looking to do.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

First and foremost...

:ILA:

And yes... you guys are the bomb diggity! ;) I felt like I needed to post my program because otherwise what's the point of asking and never having the question / answer provided... Here's a program to delete temp files and extra profiles in XP.

!!! Use on a test device ONLY !!!

I'm NEW so I know I could've looped through dir1 to dir3... it's just easier for me to read right now and loops in loops are tough so...

Notes For Program Below:

Password is "test123" obviously.

Deletes files and folders in the following:

$dir1 = "C:Cache_Directory"

$dir2 = "C:Temp"

$dir3 = "C:WindowsTemp"

$sPath1 = "C:Documents and Settings"

Excluded Folders in "C:Documents and Settings" are..

Administrator;

All Users;

Default User;

LocalService;

NetworkService;

CURRENT_USER or @Username;

Modify the program to suit your purpose :)

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=trash.ico
#AutoIt3Wrapper_Res_Fileversion=10.0.0.57
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/cs /cn /cf /cv /sf /sv
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <File.au3>
#include <Array.au3>
#include "RecFileListToArray.au3"
#RequireAdmin

; The above include file is not a normal of of the box autoit function "RecFileListToArray.au3" - you have to download it from autoitscript.com RecFileListToArray.au3

; Thanks Melba23 - You have my vote to include this in the next ver of AutoIT!

;Func _RecFileListToArray($sInitialPath, $sInclude_List = "*", $iReturn = 0, $iRecur = 0, $iSort = 0, $iReturnPath = 1, $sExclude_List = "", $sExclude_List_Folder = "")

Global $msgboxans1, $ProgramTitle1, $ExcludeFolders1, $dir1, $dir1array1, $dir2, $dir2array2, $dir3, $dir3array3, $sPath1, $sPath1Array1

$ProgramTitle1 = "Delete Temp Files"

Call ("PassFunc1")

Func PassFunc1()

$pass1=InputBox($ProgramTitle1,'Password:','password','*',200,200)

If @error Then
Exit
EndIf

If Not @error and $pass1=='test123' Then
Call ("IsThisTestPc1")
EndIf

If $pass1 <> 'test123' Then
SplashTextOn($ProgramTitle1, "Password Incorrect - 5 Second Delay", 400, 40, -1, -1, 2, "", 0)
Sleep(5000)
SplashOff()
Call ("PassFunc1")
EndIf

EndFunc


Func IsThisTestPc1()

$msgboxans1 = MsgBox(4, $ProgramTitle1, "! ! ! Test PC's ONLY ! ! !" & @CR & @CR & "Is this a test pc?")
If $msgboxans1 = 6 Then Call ("DeleteFiles1")
If $msgboxans1 = 7 Then
MsgBox (0, $ProgramTitle1, "Please move to a test device.")
Exit
EndIf
EndFunc

Func DeleteFiles1()

; Directory 1

$dir1 = "C:Cache_Directory"

SplashTextOn ($ProgramTitle1, "Checking Directory: " & $dir1, 400, 40, -1, -1, 2, "", 10)
Sleep(2000)
SplashOff()

$dir1array1 = _RecFileListToArray($dir1, "*", 0, 1, 0)

If IsArray($dir1array1) <> 1 Then Call ("DeleteFiles2")

If IsArray($dir1array1) = 1 Then

; Uncomment the following line to see file / folder results...

;_ArrayDisplay ($dir1array1, "The array")

SplashTextOn ($ProgramTitle1, "Deleting files from " & $dir1, 400, 40, -1, -1, 2, "", 10)
Sleep(2000)
For $I1 = 1 To $dir1array1[0] ; $dir1array1 is an array and element [0] holds the number of files / dirs
DirRemove ($dir1 & $dir1array1[$I1], 1)
Next

FileDelete ($dir1)

SplashOff()

Call ("DeleteFiles2")

EndIf

EndFunc



Func DeleteFiles2()

; Directory 2

$dir2 = "C:Temp"

SplashTextOn ($ProgramTitle1, "Checking Directory: " & $dir2, 400, 40, -1, -1, 2, "", 10)
Sleep(2000)
SplashOff()

$dir2array2 = _RecFileListToArray($dir2, "*", 0, 1, 0)

If IsArray($dir2array2) <> 1 Then Call ("DeleteFiles3")

If IsArray($dir2array2) = 1 Then

SplashTextOn ($ProgramTitle1, "Deleting files from " & $dir2, 400, 40, -1, -1, 2, "", 10)
Sleep(2000)
For $I2 = 1 To $dir2array2[0]
DirRemove ($dir2 & $dir2array2[$I2], 1)
Next

FileDelete ($dir2)

SplashOff()

Call ("DeleteFiles3")

EndIf

EndFunc

Func DeleteFiles3()

; Directory 3

$dir3 = "C:WindowsTemp"

SplashTextOn ($ProgramTitle1, "Checking Directory: " & $dir3, 400, 40, -1, -1, 2, "", 10)
Sleep(2000)
SplashOff()

$dir3array3 = _RecFileListToArray($dir3, "*", 0, 1, 0)

If IsArray($dir3array3) <> 1 Then Call ("DeleteProfiles1")

If IsArray($dir3array3) = 1 Then

SplashTextOn ($ProgramTitle1, "Deleting files from " & $dir3, 400, 40, -1, -1, 2, "", 10)
Sleep(2000)
For $I3 = 1 To $dir3array3[0]
DirRemove ($dir3 & $dir3array3[$I3], 1)
Next

FileDelete ($dir3)

SplashOff()

Call ("DeleteProfiles1")

EndIf

EndFunc


Func DeleteProfiles1()

$sPath1 = "C:Documents and Settings"

SplashTextOn($ProgramTitle1, "Creating file list for " & $sPath1, 400, 40, -1, -1, 2, "", 10)
Sleep (2000)
SplashOff()

$ExcludeFolders1 = "Administrator;All Users;Default User;LocalService;NetworkService;" & @Username & ";"

SplashTextOn($ProgramTitle1, "Excluding: " & $ExcludeFolders1, 800, 40, -1, -1, 2, "", 10)
Sleep (2000)
SplashOff()

;Func _RecFileListToArray($sInitialPath, $sInclude_List = "*", $iReturn = 0, $iRecur = 0, $iSort = 0, $iReturnPath = 1, $sExclude_List = "", $sExclude_List_Folder = "")

$sPath1Array1 = _RecFileListToArray($sPath1, "*", 2, 0, 0, 1, $ExcludeFolders1)

If IsArray($sPath1Array1) <> 1 Then Call ("ExitProgram1")

If IsArray($sPath1Array1) = 1 Then

For $I4 = 1 To $sPath1Array1[0]
DirRemove ($sPath1 & $sPath1Array1[$I4], 1)
Sleep (500)
SplashTextOn ($ProgramTitle1, $sPath1 & $sPath1Array1[$I4] & " has been deleted recursively.", 400, 40, -1, -1, 2, "", 10)
Sleep (2000)
SplashOff()
Next

Call ("ExitProgram1")

EndIf

EndFunc


Func ExitProgram1()

SplashTextOn ($ProgramTitle1, "Deletion Process Completed", 400, 40, -1, -1, 2, "", 10)
Sleep (2000)
SplashOff()

SplashTextOn ($ProgramTitle1, "Exiting...", 400, 40, -1, -1, 2, "", 10)
Sleep (2000)
SplashOff()
Exit
EndFunc
Edited by souldjer777

"Maybe I'm on a road that ain't been paved yet. And maybe I see a sign that ain't been made yet"
Song Title: I guess you could say
Artist: Middle Class Rut

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...