Posted: Wed May 07, 2014 2:44 pm Post subject: Find file using Dir(*.*) and Dir() Bascom AVR Version 2.0.7.
Hi all,
I have a simple sub that searches a directory and gives error if the file is not found.
Makes no sense to me why this does not work.
Here is the code.
Dim File_error As Bit 'Flag to reset if file is found
Dim Myfile As String * 12 'File I want to find
Dim Mydirectory As String * 12 'Directory I want to search
Config Submode = New
Sub Findfile(byref Filetofind As String , Byval Directory As String * 12)
Local File_read As String * 12
Chdir "\" 'Be sure we start at root
Chdir Directory 'Move to new directory
Set File_error 'Set fault flag before we begin
Print #1 , "File to find= " ; Filetofind
Fileread = Dir( "*.*") 'Get 1st file name in directory
While File_read <> "" 'loop until my file is found or end of directory
Print #1 , "Dir file= " ; File_read 'For disgnostics to see files being checked
If File_read = Filetofind Then 'If the present file name matches the search reset file_err flag and exit
Reset File_error
Exit While
End If
File_read = Dir() 'get the next file name
Wend
End Sub
The file is there and it get's printed but the check does not reset the file_error flag.
Here is what get's printed when the file is run.
File to find=ENGCFG1.mnu
Dir file= GERCFG2.MNU
Dir file= ITACFG1.MNU
Dir file= ITACFG1.SEL
Dir file= ITACFG2.MNU
Dir file= POLCFG1.MNU
Dir file= POLCFG1.SEL
Dir file= POLCFG2.MNU
Dir file= PORCFG1.MNU
Dir file= PORCFG1.SEL
Dir file= PORCFG2.MNU
Dir file= SPACFG1.MNU
Dir file= SPACFG1.SEL
Dir file= SPACFG2.MNU
Dir file= ENGCFG1.MNU 'This is the file I'm looking for
Dir file= ENGCFG1.SEL
Dir file= ENGCFG2.MNU
Dir file= FRECFG1.MNU
Dir file= FRECFG1.SEL
Dir file= FRECFG2.MNU
Dir file= GERCFG1.MNU
Dir file= GERCFG1.SEL
File_error= 1
Any idea what I'm doing wrong?
Maybe there is another simple way to do this?
Thanks,
Jerry
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum