Jump to content

Display List of Files and Allow User to Select


gruntydatsun
 Share

Recommended Posts

Hi,

I'm looking for advice on the type of structure to use to allow a user to select from a list of files.

I'm going to collect all the filenames from subfolders and present them in a single list where the user can select from them to set which files should be ignored from this point forward when copying down podcasts.

I don't need working examples, just some advice on the most suitable GUI structure to use for this job.

Below is the program I'm writing it for.

The program looks at a file showing all the podcasts previously pushed up to the phone from the pc, compares that to what exists in the pc podcast folder and copies up the difference to my phone.

Any advice on improvements to the way I did this would be appreciated too :graduated:

#Include <File.au3>
 
#Include <Array.au3>
 
;ARRAYS
dim $FolderList         ;array: list of folders in the root of podcast folder on C
dim $FileList           ;array: list of files in each folder in the podcast root on C
dim $Extinct            ;array: list of files that have already been uploaded to the phone
 
;VARIABLES
dim $podcast_root = "C:\Users\user\Documents\My Received Podcasts\"                     ;root folder where podcasts arrive on local pc
dim $bb_pods = "\home\user\podcasts"                                                    ;podcast folder on blackberry
dim $bb_gears = "\home\user\appdata\rim\gears"                                          ;google gears folder on blackberry
dim $error_mount_fail = "BB podcast folder not found.  EXITING NOW"                     ;error message for BB podcast folder not found
 
dim $write_to_log = ""
 
;DETERMINE DRIVE MAPPING FOR BLACKBERRY
$ABC = DriveGetDrive( "removable" )                                                     ;get array of removable drives
 
if IsArray($ABC) Then
    for $x = 0 to $ABC[0]                                                               ;loop through array of removable drives
        if FileExists($ABC[$x] & $bb_pods) AND FileExists($ABC[$x] & $bb_gears) then    ;confirm podcast and gears folders exist on BB
            $dest_path = $ABC[$x] & $bb_pods                                            ;set destination path to copy podcasts to
            MsgBox(1,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$dest_path' & @lf & @lf & 'Return:' & @lf & $dest_path) ;### Debug MSGBOX
 
        EndIf
    Next
Else
    msgbox(1,"PHONE FAILURE",$error_mount_fail)                                         ;there are no removable drives mounted on
    Exit                                                                                ;this machine at all. Quit.
EndIf
 
 
;PREPARE ARRAY OF FOLDER NAMES
$FolderList = _FileListToArray($podcast_root,"*",2)                                     ;get listing of folder names in local podcast folder
 
_FileReadToArray($podcast_root & "uploaded.txt",$Extinct)                               ;read text file of prevoiusly uploaded content
 
$previously_copied = 0                                                                  ;flag showing file has been copied to phone previously
 
for $x = 1 to $FolderList[0]                                                            ;loop thru array of child folders in local podcast root folder
    $FileList =_FileListToArray($podcast_root & $FolderList[$x],"*.mp3")                ;get array of mp3 files in this child folder
    for $y = 1 to $FileList[0]                                                          ;loop thru array of mp3s in download folder on c
        $previously_copied = 0                                                          ;FLAG: has this file been copied to the phone before
        for $z = 1 to $extinct[0]                                                       ;loop thru array of mp3s previously uploaded to phone
            if $FileList[$y] = $extinct[$z] Then                                        ;if this file has been uploaded to phone before
                $previously_copied = 1                                                  ;FLAG: This file has previously been uploaded to phone
                ExitLoop                                                                ;stop searching extinct array as this file was previously uploaded
            EndIf
        next
        if $previously_copied = 0 Then
            msgbox(1,"UPLOADING NEW FILE","Uploading: " & $Podcast_Root & $FolderList[$x] & "\" & $FileList[$y],3)  ;notify of intent to copy
            _FileCopy($Podcast_Root & $FolderList[$x] & "\" & $FileList[$y], $dest_path)                            ;upload file to phone
            $handle = FileOpen($podcast_root & "uploaded.txt",1)
            FileWriteLine($handle,"Uploaded at " & @MDAY & "/" & @MON & "/" & @YEAR & " at " & @HOUR & ":" & @MIN & @CRLF)
            FileWriteLine($handle,$FileList[$y] & @CRLF & @CRLF)
            FileClose($handle)
            $write_to_log &= "Uploaded " & $FileList[$y] & " at " & @HOUR & ":" & @MIN & " on " & @MDAY & "/" & @MON & "/" & @YEAR & @CRLF
        EndIf
        $previously_copied = 0
    next
next
 
if $write_to_log = "" Then
    msgbox(1,"NOTHING TO DO","There are no new podcasts to upload")
Else
    msgbox(1,"UPLOAD RESULTS",$write_to_log)
EndIf
 
 
 
Func _FileCopy($source, $target)
    Local $FOF_RESPOND_YES = 16
    Local $FOF_SIMPLEPROGRESS = 256
    $winShell = ObjCreate("shell.application")
    $winShell.namespace($target).CopyHere($source, $FOF_RESPOND_YES)
EndFunc
Link to comment
Share on other sites

  • Moderators

gruntydatsun,

advice on the type of structure to use to allow a user to select from a list of files...

user can select from them to set which files..

I assume you want multiple selections, so you are essentially limited to a ListView as a TreeView can have only one selection. _GUICtrlListView_GetSelectedIndices will give you those items selected by the user. :graduated:

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

  • Moderators

gruntydatsun,

Searching (the box is at top right ;)) brought up this, but I have never used it. :graduated:

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

  • Moderators

gruntydatsun,

If you had mentioned that you only wanted to read the file properties, I would have pointed you here. :graduated:

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

This is what I use to get extended file properties, it's a modification of a function that I believe was created by Simucal, that should return any and all file properties for any version of Windows up to and including Windows 7. The original only worked well for the first 100 properties under XP.

;===============================================================================
; Function Name.....: _FileGetProperty
; Description.......: Returns a property or all properties for a file.
; Version...........: 1.0.2
; Change Date.......: 2008-07-28
; AutoIt Version....: 3.2.12.1
;
; Parameter(s)......: $S_PATH - String containing the file path to return the property from.
;                     $S_PROPERTY - [optional] String containing the name of the property to return. (default = "")
; Requirements(s)...: None
; Return Value(s)...: Success: Returns a string containing the property value.
;                       If $S_PROPERTY is empty, an two-dimensional array is returned:
;                         $av_array[0][0] = Number of properties.
;                         $av_array[1][0] = 1st property name.
;                         $as_array[1][1] = 1st property value.
;                         $av_array[n][0] = nth property name.
;                         $as_array[n][1] = nth property value.
;                     Failure: Returns 0 and sets @error to:
;                       1 = The folder $S_PATH does not exist.
;                       2 = The property $S_PROPERTY does not exist or the array could not be created.
;                       3 = Unable to create the "Shell.Application" object $objShell.
;
; Author(s).........: - Simucal <Simucal@gmail.com>
;                     - Modified by: Sean Hart <autoit@hartmail.ca>
;                     - Modified by: teh_hahn <sPiTsHiT@gmx.de>
; Company...........: None
; URL...............: None
; Note(s)...........: None
;===============================================================================
Func _FileGetProperty(Const $S_PATH, Const $S_PROPERTY = "")
If Not FileExists($S_PATH) Then Return SetError(1, 0, 0)
Local Const $S_FILE = StringTrimLeft($S_PATH, StringInStr($S_PATH, "\", 0, -1))
Local Const $S_DIR = StringTrimRight($S_PATH, StringLen($S_FILE) + 1)
Local Const $objShell = ObjCreate("Shell.Application")
If @error Then Return SetError(3, 0, 0)
Local Const $objFolder = $objShell.NameSpace($S_DIR)
Local Const $objFolderItem = $objFolder.Parsename($S_FILE)
If $S_PROPERTY Then
  For $I = 0 To 300
   If $objFolder.GetDetailsOf($objFolder.Items, $I) = $S_PROPERTY Then Return $objFolder.GetDetailsOf($objFolderItem, $I)
  Next
  Return SetError(2, 0, 0)
EndIf
Local $av_ret[1][2] = [[1]]
For $I = 0 To 300
  If $objFolder.GetDetailsOf($objFolder.Items, $I) Then
   ReDim $av_ret[$av_ret[0][0] + 1][2]
   $av_ret[$av_ret[0][0]][0] = $objFolder.GetDetailsOf($objFolder.Items, $I)
   $av_ret[$av_ret[0][0]][1] = $objFolder.GetDetailsOf($objFolderItem, $I)
   $av_ret[0][0] += 1
  EndIf
Next
If Not $av_ret[1][0] Then Return SetError(2, 0, 0)
$av_ret[0][0] -= 1
Return $av_ret
EndFunc   ;==>_FileGetProperty

EDIT: Forgot to include the UDF header so you'd know how to use it.

REDIT: Had to reformat the code because the forum software sucks so badly.

Edited by BrewManNH

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

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