Jump to content

GetDirectoryListing (but exclude named directories)

Recommended Posts

Hi Guys

Wonder if anyone can help me? I am trying to get a directory listing. I'm using this to build file paths then I plan to delete files. I want to exclude particular directories. I know the name of these so could hard-code. What's the best way to do this?


#Include <File.au3>
#Include <Array.au3>
Func GetDirectory()
Global $ini = @ScriptDir & "/settings.ini"
Global $root =  "c:\autoit\"
$FileList=_FileListToArray($root, "*", 2)
If @Error=1 Then
    MsgBox (0,"","No Files\Folders Found.")
; Skip the first value (count) and output directories to file
For $i = 1 To UBound($FileList)-1
   FileWrite($ini, $root & $FileList[$i]&@CRLF)
Link to post
Share on other sites

You could use Melba23's RecFileListToArray UDF which has the option to exclude files/directories by name or with wildcards, and also will search subfolders of the path you give it if wanted.

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 post
Share on other sites

Set your files in question in its own array '$file[]' in my example, search your $FileList for those files and remove them from the list. Then re-calculate the number of files into the first element of your $FileList, and then perform your DirRemove() on your $FileList. Some example code for you.

EDIT: Talking about folders =D

Global $file[2], $_dim
Global $pathFolders = "C:RelativePathTo"
$file[0] = "folder1"
$file[1] = "folder2"
_ArrayDisplay($aTest) ; Check original file list
For $files in $file
    $_dim = _ArrayDelete($FileList, _ArraySearch($FileList, $files))
$FileList[0] = $_dim - 1
_ArrayDisplay($aTest) ; Check final file list
$i = 0
For $files in $FileList
    If $i = 0 Then
        DirRemove($pathFolders & $files, 1)
Edited by mechaflash213

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”


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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...