View previous topic :: View next topic |
Author |
Message |
njepsen
Joined: 13 Aug 2007 Posts: 469
|
Posted: Fri Jan 11, 2013 12:48 am Post subject: Dir(*.*) and Dir() |
|
|
The help says that Dir() will return an empty string when there are no more files to read. This is true BUT not in some circumstances.
I have written a little loop to do a directory of an SD card. Code: |
Do
Chdir "\"
Filecount = 0
Tempstr = ""
Tempstr = Dir( "*.*") 'get first file name
While Tempstr <> ""
Incr Filecount
Print #1 , ">> " ; Tempstr 'list file
Tempstr = Dir()
Reset Watchdog
Wend
Print #1 , ">> " ; Filecount ; "files"
Call Timedelay(1000)
Print #1 , ""
Loop |
Which works fine, and the following printout appears on screen every second:
Code: |
>> LOG2013.
>> CACHE.
>> ERRORLOG.
>> 3files
>> LOG2013.
>> CACHE.
>> ERRORLOG.
>> 3files
etc
|
However if I unplug the SD card while the loop is running, it continues to give me the SAME printout - ie it suggest it is still reading the SD card which course it is not. This tells me that dir() does not check if there is a directory present, and that the old values are not cleared before a new Dir() read is done ??I have no idea where the txt is coming from, because filecount and tempstr are cleared every time thru' the loop. _________________ Neil |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Fri Jan 11, 2013 10:12 am Post subject: |
|
|
Maybe Josef can comment on it? _________________ Mark |
|
Back to top |
|
|
njepsen
Joined: 13 Aug 2007 Posts: 469
|
Posted: Fri Jan 11, 2013 10:25 am Post subject: |
|
|
Thanks Mark. Look forward to it.
I have made a reply to 2 previous posts of mine, which 'd appreciate your views on:
PostPosted: Mon Dec 10, 2012 4:19 pm Post subject: Help Txt for config serialin confusing
PostPosted: Thu Dec 13, 2012 9:29 pm Post subject: IDE search panel bug
In the 2nd one I have included a (bad) U-tube clip showing the problem. _________________ Neil |
|
Back to top |
|
|
oe9vfj
Joined: 17 Jun 2004 Posts: 269 Location: Austria, Hard
|
Posted: Fri Jan 11, 2013 6:58 pm Post subject: |
|
|
Hi,
If AVR-DOS is working with a disk, it reads the according sector into the RAM and works with that copy in the RAM unless a function needs another sector. Than AVR-DOS writes the RAM-image of the sector to the disk back, if something was changed in this sector and reads the new sector into the RAM.
Each opened file has its own RAM-Area and also the FAT and Directory depending of the Parameter Csepfathandle.
One directory-sector can hold 16 Directory-Entries, so in your Situation AVR-DOS can load all information from the RAM-image of the directory-Sector and there is no reason to load the information from the card again. Only at the point, when AVR-DOS needs a new Sector from the card, it will detect, that no card is present.
IF you want to detect the removing of the card immediately, you have to do it by checking the card-present line if your sd-card slot provide it.
best regards
Josef _________________ regards Josef
DOS - File System for BASCOM-AVR on http://members.aon.at/voegel |
|
Back to top |
|
|
njepsen
Joined: 13 Aug 2007 Posts: 469
|
Posted: Fri Jan 11, 2013 9:35 pm Post subject: |
|
|
Hi Joseph and thanks for your reply. I was aware of the fix, and I do already monitor the SD card socket switch. However i was more concerned with a faulty card. Currently i do a write to the card, and 15 minutes later the card info sent to a server. i wanted to make sure the dir data i was sending was the new data and not the old data, because it seems that if dir() can't read the card for some reason ( eg faulty) it presents the previous read as valid ? Is there any way i can clear the old dir() info and force a new read of the Sd card. _________________ Neil |
|
Back to top |
|
|
oe9vfj
Joined: 17 Jun 2004 Posts: 269 Location: Austria, Hard
|
Posted: Mon Jan 14, 2013 3:44 pm Post subject: |
|
|
Hi,
If you detect a change of the card, you should use DriveInit and InitFileSystem to restart AVR-DOS with the new card. Otherwith it could happen, that you corrupt the new Card, if you make write operations to the new card with card information of the old card.
best regards
Josef _________________ regards Josef
DOS - File System for BASCOM-AVR on http://members.aon.at/voegel |
|
Back to top |
|
|
njepsen
Joined: 13 Aug 2007 Posts: 469
|
Posted: Thu Feb 20, 2014 4:06 am Post subject: |
|
|
A further point of clarification ( one year later).
The help says: Quote: | The first function call needs a file mask. All other calls do not need the file mask. In fact when you want to get the next filename from the directory, you must not provide a mask after the first call.
|
Obviously "you must not provide a mask after the first call" must terminate at some stage. Is this true until the next SDinit or until the next chdir? In other words, after a dir(*.*), subsequently dir() will return the next file each time until all done. However if I change directories, do i do dir(*.*) or just dir() to get the next filename? The reason i ask this seemingly trivial question is that I have a loop like this:
Code: |
chdir"\"
chdir somefilename
myfilename = dir(*.*) ' get the first file
do
dosomething
dosomething
dosomething
myfilename = dir() 'get the next file
if myfilename="" then exit do
loop |
This code works fine, BUT if in the line "dosomething" I call another sub which involves some file handling, the dir() that follows gives unexpected results. _________________ Neil |
|
Back to top |
|
|
njepsen
Joined: 13 Aug 2007 Posts: 469
|
Posted: Thu Dec 15, 2016 2:30 am Post subject: |
|
|
if a directory does not yet exist and you change to that directory and call dir*.*,
the filename becomes ".", so any followng code may give an unexpected result.
In the code below, I am expecting a folder with the const name cachefoldernamestr, and if it is not empty
I connect to the server and POST the files.
However if for some reason, the directory doesnt yet exist ( a new SD card for example), then my
myfilename becomes ".", which means there is an unnecessary TCP connect, for a non existent file.
Code: |
Chdir "\" 'root
Chdir Cachefoldernamestr 'my data
Myfilename = Dir( "*.*") 'get first file
Print #1 , ">> myfilename = " ; Myfilename
If Myfilename = "" Then
Print #1 , ">> no files left to send"
Exit Do 'exit when no files left to send
else
call tcp_connect(main_server , 80) 'connect to the server
etc
etc
end if
|
_________________ Neil |
|
Back to top |
|
|
|