Jump to content

Selecting Files


zcwight
 Share

Recommended Posts

As stated in other quires, I'm quite new to this, so I'm in need of a little help. All I'm after is a line of code that will do one of the following:

Select a file at random from a folder, open it, continue with the rest of the script I've written and then delete that file, then loop.

Or, Select the top file (preferred option) and then do the above^

All I'm after is a line that will select a file following one of the above rules.

Something like this would be perfect:

 

RandomSelect (C:\Users\User\Desktop\Folder) *.html

Deletefile (C:\Users\User\Desktop\Folder) (above file)

Thankyou

 

PS: If its not possible for Autoit, would it be possible for any other language?

Edited by zcwight
Adding PS
Link to comment
Share on other sites

  • Moderators

zcwight,

Use _FileListToArray to get the folder content - and then either use the first file or use Random to select one. Once you have finished with the file, use FileDelete/Recycle to remove it.

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

Ok, sorry, but would i be able to get an example of this, ive been looking at the Autoit Help file, and can't seem to figure it out.

could you please write out exactly waht i'd need using things like ~insert directory here~?

Will this allow me to use only one particular file?

what I have is a folder with around 15 .html files in it, and i need for the script to single out one (doesnt matter which one) and ONLY use that one until the end of the script, where it will delete it, and then start again, but with another.

Link to comment
Share on other sites

  • Moderators

zcwight,

Think of the old saying: "Give a man a fish, you feed him for a day; give a man a net and you feed him forever". We try to be net makers and repairers, not fishmongers.

You say you have looked in the help file - the example for _FileListToArray shows exactly how to get and display a list of the files in a folder. Did you try running it? Did you try to set your required folder path and filename filter? If you have done this and still have problems, which bit of the code did you not understand?

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

55 minutes ago, Melba23 said:

zcwight,

Use _FileListToArray to get the folder content - and then either use the first file or use Random to select one. Once you have finished with the file, use FileDelete/Recycle to remove it.

M23

I copied the help file text and changed the parameters to be what I needed them to be and get the error "path was invalid" heres what i wrote:

Func Example()
    ; List all the files and folders in the desktop directory using the default parameters.
    Local $aFileList = _FileListToArray( "C:\Users\Zac\Dropbox\SoundCloud, "*"" )
    If @error = 1 Then
        MsgBox($MB_SYSTEMMODAL, "", "Path was invalid.")
        Exit
    EndIf
    If @error = 4 Then
        MsgBox($MB_SYSTEMMODAL, "", "No file(s) were found.")
        Exit
    EndIf
    ; Display the results returned by _FileListToArray.
    _ArrayDisplay($aFileList, "$aFileList")
EndFunc   ;==>Example

also with the:

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

sorry, I forgot to include them

Edited by zcwight
Link to comment
Share on other sites

  • Moderators

zcwight,

Splendid - so you now have an array containing the file names. As I mentioned earlier, you can either use the first one in the list ( $aFileList[1] ) or you can choose a random one like this:

#include <MsgBoxConstants.au3>

; Set a HotKey to escape the infinite loop
HotKeySet("{ESC}", "_Exit")

; Here is the array with the files
Global $aFileList[5] = [4, "File_1", "File_2", "File_3", "File_4"]

; and now we choose a random file
While 1
    ; This will get an integer number between 1 and the number of files in the list
    $iRandom_Index = Random(1, $aFileList[0], 1)
    ; And here we display it
    MsgBox($MB_SYSTEMMODAL, "Random", $aFileList[$iRandom_Index])
WEnd

; This function runs when we press {ESCAPE}
Func _Exit()
    Exit
EndFunc

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

Ok, so now I get a message box with a number, how do i select that to be the file to use for the rest of the script? And is there any way to avoid message boxes, I'm planning on having this script run on a timer, and would like as little interaction as possible.

Link to comment
Share on other sites

  • Moderators

zcwight,

The MsgBox is just there to show you how it works - which part of the MsgBox command do you think holds the selected filename? Once you know that you can use that to act on the file else where in the script.

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

zcwight,

Not at all - the list is just a list. If you look at the code I posted, you will see that I use Random to get an integer number which will select one of the files - if you do not see how then look at Random in the Help file and check how I set the parameters. That is how one of the files gets selected.

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

×
×
  • Create New...