darknezz21

_Filelistoarray remove extensions of results?

6 posts in this topic

I'm trying to remove the extensions of the files returned with _Filelistoarray but am not sure how to express this.

Also tried _RecFileListToArray by Melba23 as suggested in the link I found below but I don't see an option for this functionality.

Here is what Ive tried so far, any suggestions?
 

;Local $aFileList = _FileListToArray(@ScriptDir, "*.txt")
Local $aFileList = _RecFileListToArray(@ScriptDir, "*.*", 0, 0, 0, 1, "*.au3", "")

   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")

MsgBox($MB_SYSTEMMODAL, "", $aFileList[1])

 

Share this post


Link to post
Share on other sites



darknezz21,

The comment refers to excluding certain file extensions from the returned array - not removing the extensions from the returned files.

My ChooseFileFolder UDF does have this functionality when displaying a file list (I use it when listing mp3 files) but that is not a lot of use to you. I think you are going to have to remove the extensions in a loop like this:

#include <File.au3>

Local $aFileList = _FileListToArrayRec(@ScriptDir, "*.*|*.au3", $FLTAR_FILES, $FLTAR_NORECUR, $FLTAR_NOSORT)

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

; Now loop and remove the extension
For $i = 1 To $aFileList[0]
    $aFileList[$i] = StringRegExpReplace($aFileList[$i], "^.*\\|\..*$", "")
Next

_ArrayDisplay($aFileList, "$aFileList")

MsgBox($MB_SYSTEMMODAL, "", $aFileList[1])

Note that the deprecated  _RecFileListToArray UDF is now part of the standard UDFs (with a slightly different name) and has a different syntax for the excluded files and folders as you can see - look in the Help file for more details.

M23

 

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I'm having trouble getting it to edit the .txt extensions off still. Here is basically what was tried. I also tried the .txt without the wildcard in front but it's the same.

Local $aFileList = _RecFileListToArray(@ScriptDir, "*.*", 1, 1, 1, 1, "*.au3", "")

$post = $aFileList[1]

; Now loop and remove the extension
For $i = 1 To $post
    $aFileList[$i] = StringRegExpReplace($aFileList[$i], "*.txt", "")
Next

_ArrayDisplay($aFileList, "$aFileList")

 

Edited by darknezz21

Share this post


Link to post
Share on other sites

darknezz21,

Why are you still using my old UDF? As I explained above, it is now deprecated and you should use the standard _FileListToArrayRec UDF.

And of course the RegEx will not work as you have coded it - the pattern will never match. If you leave the command exactly as I posted it will work.

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

mikell,

Of course you may - always ready to learn.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


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