Jump to content

Locate File Types


Go to solution Solved by Melba23,

Recommended Posts

Problem:

Users are saving music and video files on my servers and it is taking up too much space. The company allows them to save some, but not this much.

Solution:

I'm trying to write an AutoIT script that can look at all files and folders on a drive and return the folder name and number of file types: .avi, .mp3 and so on. It would be helpful if this script to save the results to a log file so the IT team can send emails to the users or managers asking them to remove the files.

If you know if a template or script that is close to my needs please let me know.

Thank You

Link to comment
Share on other sites

You can always change dirs to the root of the folder you want to search from, and run command:

dir /s *.avi

dir /s *.mp3

It's quick...else you would have to look for the _filelisttoarrayrecursive function...I believe it's in the beta, and newer releases, but I'm using an older autoit version, so it's not there yet.

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

right now I feel like such a newbie. I can't get this code to work and I have now botched it so bad I need another set of eyes please. All I'm trying to do is build a small GUI app that will allow a user to enter the path and file type and the app will recurse through the folders and return all the files of that type. I have this close to working but I'm lost on the search functions. Any would be great. I did look over the examples before asking for help.

Thanks

#include <Array.au3> ; Only required to display the arrays
#include <File.au3>
#include <MsgBoxConstants.au3>
#include <MsgBoxConstants.au3>
#include <GUIConstants.au3>

#RequireAdmin

Example()

Func Example()

    ; Places the input box in the top left corner displaying the characters as they
    ; are typed.

 Local $sValue1 = InputBox("File Search", "What File Extension Are You Looking For?", "", "", _
             -1, -1, -1, 0)
   Local $sValue2 = InputBox("File Search", "Enter The File Path?", "", "", _
             -1, -1, -1, 0)

    ; Display the result.
   MsgBox($MB_SYSTEMMODAL, "", $sValue2 & $sValue1)

 Local $sValue1 = StringLeft($sValue1, StringInStr($sValue1, "", Default, -1))
   If StringRight($sValue2, 5) = "beta\" Then
       $sValue2 = StringTrimRight($sValue2, 5)
   EndIf
 ConsoleWrite($sValue2 & @CRLF)

    ; A sorted list of all files and folders in the Userdata1 Location
    Local $aArray = _FileListToArrayRec($sValue2 ,$FLTAR_FILESFOLDERS, $FLTAR_RECUR, $FLTAR_SORT)
    _ArrayDisplay($aArray, "Sorted tree")


    ; And now ignoring the "Include" folder
   ; $aArray = _FileListToArrayRec($sMusicFind, "*||include", $FLTAR_FILESFOLDERS, $FLTAR_RECUR, $FLTAR_SORT)
   ; _ArrayDisplay($aArray, "No 'Include' folder")

    ; A sorted list of all but the .exe files in the \AutoIt3 folder
   ; $aArray = _FileListToArrayRec($sMusicFind, "*|*.exe", $FLTAR_FILES, $FLTAR_NORECUR, $FLTAR_SORT)
   ; _ArrayDisplay($aArray, "Non .EXE files")

    ; And here are the .exe files we left out last time
  ;  $aArray = _FileListToArrayRec($sMusicFind, "*.exe", $FLTAR_FILES)
   ; _ArrayDisplay($aArray, ".EXE Files")

    ; A test for all folders and .exe files only throughout the folder tree, omitting folders beginning with I (Icons and Include)
   ; $aArray = _FileListToArrayRec($sMusicFind, "*.exe||i*", $FLTAR_FILESFOLDERS, $FLTAR_RECUR, $FLTAR_SORT)
  ;  _ArrayDisplay($aArray, "Recur with filter")

    ; Look for icon files - but exlude the "Icons" folder
  ;  $aArray = _FileListToArrayRec($sMusicFind, "*.ico||ic*", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_SORT)
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "Ooops!", "No ico files found")
    Else
        _ArrayDisplay($aArray, "Icon files not in 'Icons' folder")
    EndIf

    ; And to show that the filter applies to files AND folders when not recursive
   ; $aArray = _FileListToArrayRec($sValue1, "*.mp3", $FLTAR_FILESFOLDERS, $FLTAR_NORECUR, $FLTAR_SORT)
   ; _ArrayDisplay($aArray, "Non-recur with filter")

    ; The filter also applies to folders when recursively searching for folders
   ; $aArray = _FileListToArrayRec($sMusicFind, "Icons", $FLTAR_FOLDERS, $FLTAR_RECUR, $FLTAR_SORT)
   ; _ArrayDisplay($aArray, "Folder recur with filter")

    ; Note the exlude_folder parameter is ignored when looking for folders - "Icons" will be excluded but "Include" will still be there
   ; $aArray = _FileListToArrayRec($sMusicFind, "*|ic*|i*", $FLTAR_FOLDERS, $FLTAR_RECUR, $FLTAR_SORT)
  ;  _ArrayDisplay($aArray, "'Icons' out - 'Include' in")

    ; The root of C:\Windows showing hidden/system folders
   ; $aArray = _FileListToArrayRec("C:\Windows\", "*", $FLTAR_FOLDERS)
   ; _ArrayDisplay($aArray, "Show hidden folders")

    ; The root of C:\Windows omitting hidden/system folders
  ;  $aArray = _FileListToArrayRec("C:\Windows\", "*", $FLTAR_FOLDERS + $FLTAR_NOHIDDEN + $FLTAR_NOSYSTEM)
  ;  _ArrayDisplay($aArray, "Hide hidden folders")
EndFunc   ;==>Example
Edited by RBrown1375
Link to comment
Share on other sites

  • Moderators
  • Solution

RBrown1375,

This should give you the idea: :)

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

Example()

Func Example()

    Local $sExt = InputBox("File Search", "What File Extension Are You Looking For?")
    Local $sPath = InputBox("File Search", "Enter The File Path?")

    ; Display the result.
    MsgBox($MB_SYSTEMMODAL, "", $sPath & @CRLF & $sExt)

    ; A sorted list of all files
    Local $aArray = _FileListToArrayRec($sPath, "*." & $sExt, $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_SORT)

    If @error Then
        MsgBox($MB_SYSTEMMODAL, "Ooops!", "No files found")
    Else
        _ArrayDisplay($aArray, "Sorted tree")
    EndIf

EndFunc   ;==>Example
Please ask if you have any questions. :)

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

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...