Jump to content

FileFindFirstFile, FileFindNextFile and square brackets?


Recommended Posts

Hello, I've read several topics on this forum, but I can't find a solution so far.

I've got an application creating PDF's from my jpeg files. First I count the files using DirGetSize, but after that I want to loop through the files using FileFindFirstFile and FileFindNextFile. Now comes the problem: I've got many filenames starting with a square bracket (i.e. "[my_categorie]myfilename.jpg"). I came to the solution these functions don't read these files. When I put an alphabetical character as first character in the filename, it works well.

Does anyone has a solution to this problem? Thanks in advance!

Link to comment
Share on other sites

You can use also _FileListToArray() instead of FileFindFirstFile() and FileFindNextFile(), and work well with this kind of filenames.

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

$DIR = FileSelectFolder("Select","")
If Not @error Then
    $FILE = _FileListToArray($DIR)
    _ArrayDisplay($FILE)
EndIf
Edited by Andreik

When the words fail... music speaks.

Link to comment
Share on other sites

  • Moderators

ChristiaanT,

FileFindFirstFile and FileFindNextFile work fine with [filenames] on my system. Could you post the code you are having problems with so we could take a look?

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

Hmm, this is my code I'm using now:

As you can see, I use "*" instead of "*.*" to disable filter at all, but with no results.

Shows the filenames of all files in the current directory
$filelist = FileFindFirstFile($cover_folder & "\*")  

; Check if the search was successful
If $filelist = -1 Then
    _ThrowError("Geen bestanden gevonden, probeer opnieuw a.u.b.", 1)
    Exit
EndIf

While 1
    $file = FileFindNextFile($filelist)
    If @error Then ExitLoop

To test I've got 4 jpegs in a the $cover_folder, named as following:

[All]_my_cover.jpg

[All]_my_cover_test.jpg

Foo_bar_file_cover.jpg

Test_cover.jpg

The while loop wants to continue, but the $file var starts with Foo_bar_file_cover.jpg and ends with Test_cover.jpg. It completely ignores the first two.

@Andreik, do I need to download the _FileListToArray() function? Or is it a build-in function? I don't see it in the documentation of AutoIt?

Link to comment
Share on other sites

You have to use #include<file.au3> at the top of your script

In the help file look under User Defined Functions >> File Management

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

  • Moderators

ChristiaanT,

Here is the code I used in my file-finding script (which looks very much like yours) and it finds files renamed with the filenames you posted without problem!

; Get search handle
$hSearch = FileFindFirstFile($sCurrentPath & "*") ; $CurrentPath already ends in \
; If folder empty move to next in list
If $hSearch = -1 Then ContinueLoop
; Search folder
While 1
    $sName = FileFindNextFile($hSearch)
    ; Check for end of folder
    If @error Then ExitLoop

As to _FileListToArray, it is in the File.au3 include file and is covered in the full Help file. Use AutoIt3Help.exe to open the Help file and you get all the UDF Help as well.

However, _FileListToArray, uses FileFindFirstFile and FileFindNextFile to work - I will be intrigued to see if it works for you! Could you post all of your script - perhaps there is something else which is causing a problem?

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

Guys, I made it using the _FileListToArray function (very simple actually). I haven't got the time to spend much more time in it. I know this isn't solving the problem with the brackets in the functions, but maybe it's in my app then? I'll leave it for this...

Thanks for the usefull suggestions/solutions! This is my first time using AutoIt, it works very handy I must say. I definetely gonna use it in future projects! Contact y'all then, maybe >_< Thanks!

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