Liberty BASIC Community Forum
« FILES command tests »

Welcome Guest. Please Login or Register.
Nov 20th, 2017, 12:47pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: FILES command tests  (Read 165 times)
Harbinger
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 27
xx FILES command tests
« Thread started on: Aug 29th, 2016, 11:49am »

While attempting to understand how the FILES command puts the file info in info$ (or whichever array name you use), i ran some tests, and found out some interesting tidbits. This may exist elsewhere, but it's not in the LB Helpfile, so maybe this should be added.

I needed a list of the images in a folder (which were only filled with images) because my application would have a Previous and Next Image button to navigate through the files, and show a preview of the image. The FILES command does an excellent job of parsing the file list, and i could easily use the array directly if there were mixed file types. The Helpfile explained how to do this.

What's not known is how the file list is sorted by the FILES command. I thought it was by the name of the file, but things got a little interesting when i tested what it would do with different numberings.

My images were sorted like this:

image01.bmp
image02.bmp
and so on, with a few of the files actually being shortcuts to images in another folder...

I ran this program:
Code:
DIM info$(0,0)

files "H:\pix\bmp archives\images",info$()

for j = 0 to 3
print "Info$(";j;",-)"
    for i = 0 to 3
     print i;" = ";info$(j,i)
    next i
next j
wait
 


and got this result in the mainwindow:

Code:
Info$(0,-)
0 = 30
1 = 0
2 = H:\
3 = pix\bmp archives\images\
Info$(1,-)
0 = image01.bmp
1 = 4214
2 = 02/07/08 06:09:24 PM
3 = a
Info$(2,-)
0 = image10.BMP
1 = 4216
2 = 02/24/08 04:45:56 AM
3 = a
Info$(3,-)
0 = image11.BMP
1 = 3624
2 = 02/24/08 03:30:32 PM
3 = a
Info$(4,-)
0 = image12.bmp
1 = 4216
2 = 02/15/10 02:02:36 PM
3 = a
Info$(5,-)
0 = image15.bmp.lnk
1 = 853
2 = 06/07/14 07:34:22 PM
3 = a
Info$(6,-)
0 = image17.bmp
1 = 4216
2 = 02/15/10 02:43:52 PM
3 = a
Info$(7,-)
0 = image18.bmp
1 = 4214
2 = 02/07/08 06:10:18 PM
3 = a
Info$(8,-)
0 = image29.BMP
1 = 3624
2 = 02/24/08 02:55:02 PM
3 = a
Info$(9,-)
0 = image31.bmp
1 = 4214
2 = 02/07/08 06:11:18 PM
3 = a
Info$(10,-)
0 = image41.bmp
1 = 4216
2 = 01/23/08 06:51:08 PM
3 = a
Info$(11,-)
0 = image42.bmp
1 = 4216
2 = 01/23/08 06:51:08 PM
3 = a
Info$(12,-)
0 = image44.bmp
1 = 4216
2 = 01/23/08 06:51:08 PM
3 = a
Info$(13,-)
0 = image45.bmp
1 = 4216
2 = 01/23/08 06:51:08 PM
3 = a
Info$(14,-)
0 = image49.bmp
1 = 4216
2 = 02/20/07 11:02:28 PM
3 = a
Info$(15,-)
0 = image50.BMP
1 = 4558
2 = 07/13/10 01:59:20 PM
3 = a
Info$(16,-)
0 = image51.BMP
1 = 4216
2 = 02/24/08 05:21:36 PM
3 = a
Info$(17,-)
0 = image52.BMP
1 = 4216
2 = 02/24/08 04:59:26 PM
3 = a
Info$(18,-)
0 = Thumbs.db
1 = 8192
2 = 07/24/11 10:01:00 PM
3 = hsa
Info$(19,-)
0 = image15.bmp
1 = 4216
2 = 02/15/10 01:24:40 PM
3 = a
Info$(20,-)
0 = image03!.gif
1 = 389182
2 = 07/20/14 06:33:30 PM
3 = a
Info$(21,-)
0 = image17!.gif
1 = 30427
2 = 07/12/14 05:55:30 PM
3 = a
Info$(22,-)
0 = image21!.gif
1 = 20127
2 = 10/04/14 08:40:28 PM
3 = a
Info$(23,-)
0 = image02.bmp
1 = 4216
2 = 08/17/16 09:23:58 PM
3 = a
Info$(24,-)
0 = image21.bmp
1 = 4216
2 = 08/17/16 09:28:34 PM
3 = a
Info$(25,-)
0 = image25.bmp
1 = 4216
2 = 08/17/16 09:34:26 PM
3 = a
Info$(26,-)
0 = image43.bmp
1 = 4216
2 = 08/17/16 09:35:52 PM
3 = a
Info$(27,-)
0 = image46.bmp
1 = 4216
2 = 08/17/16 09:38:22 PM
3 = a
Info$(28,-)
0 = image47.bmp
1 = 4216
2 = 08/17/16 09:42:36 PM
3 = a
Info$(29,-)
0 = image48.bmp
1 = 4216
2 = 08/17/16 09:46:58 PM
3 = a
Info$(30,-)
0 = image53.BMP
1 = 4216
2 = 08/17/16 09:49:16 PM
3 = a
 


Now, the zero "row" in this case info$(0,x) has the important info. But, the string in (0,0) is SUPPOSED to be the count of files in this folder. This string here is "30" but upon counting the files in this directory, there is actually 29 (!). Why the discrepancy? There is apparently a hidden file, as shown in info$(18,-), called Thumbs.db. But my system is supposed to show ALL hidden files, as verified in Windows' "Folder Options" dialog. What is this? Does this mean that the value of the string at (0,0) can't be trusted to provide an accurate count of all files in a folder, visible or not?

I should be interesting to note that the directory paths in info$(0,2) and (0,3) end in backslashes, which is helpful, but we must account for this in our folder navigation routines that use these discoveries.
I also discovered that the FILES command doesn't care if you specify the first parameter with a trailing backslash or not. If i change the FILES command line to
files "H:\pix\bmp archives\images\",info$()

it still creates the same list.

I also discovered that the filetype filter parameter doesn't work the same as in the FILEDIALOG command.
With FILEDIALOG, you can open the Load File Windows dialog and filter what types of files you can show (and therefore load), such as "*.bmp;*.jpg;*gif". With the FILES command, however, you can only filter one type, so you would have to make three passes of the FILES command like this:
files "H:\pix\bmp archives\images","*.bmp",info$()
files "H:\pix\bmp archives\images","*.jpg",info$()
files "H:\pix\bmp archives\images","*.gif",info$()

and in-between each command you'd have to store the info you found. The Helpfile doesn't clarify that only one type can be passed at a time. (Maybe the author didn't think to account for programmers that assume too much! ;D)
This also means that if you have any shortcuts to those types (that you may have stored somewhere else), these will not be counted. You'd have to look for extension .lnk.
files "H:\pix\bmp archives\images","*.lnk",info$()

Also, i forced a re-sort of the files in Windows (Explorer) to see if the FILES command would sort it according to how it appears in Windows. In fact, if you click on the Size column in the Windows folder showing your images, to sort the files by the size in bytes rather than the name, the FILES command still sorts it by its own parameters. That's apparently hardcoded.
But it's not alphabetical. How is the FILES command listing the files in the folder?

I noticed that the third column in each row info$(x,3) shows the string "a" in all cases except the Thumbs.db in info$(18,-), which shows "hsa". What is this exactly? Can it be used for our benefit?
User IP Logged

Chris Iverson
Administrator
ImageImageImageImageImage


member is offline

Avatar

20% Cooler


Homepage PM

Gender: Male
Posts: 2282
xx Re: FILES command tests
« Reply #1 on: Aug 29th, 2016, 1:35pm »

1. Thumbs.db is a windows system file that is generated in any folder that contains pictures and uses a thumbnail preview mode. It stores the thumbnails of all the pictures in that folder.

It is marked as a hidden and a system file, so you need to configure Folder Options to show both kinds of files before you'd see it show up in Explorer.

2. Sadly, yes, FILES only lets you use one filter at a time.

3. LB will pass the list to your program in the same order that windows gave LB. There is no default specified order for data returned from the filesystem; anything interacting with that data is expected to do its own sorting. (Explorer handles its own sorting, based on how you choose to sort it. This is done by Explorer, not the filesystem.)

4. It appears to be file attributes, based on what you see there. I don't have access to the LB helpfile at the moment, so I don't know if this is documented behavior.

"a" = archive(most files will have this set, unless you have a backup program running on your system)
"h" = hidden file
"s" = system file

Thumbs.db is a hidden+system file, so it would have both flags.
« Last Edit: Aug 29th, 2016, 1:35pm by Chris Iverson » User IP Logged

"Do you believe in destiny?" - Pyrrha Nikos, RWBY
"With what wish will your Soul Gem shine?" - Kyubey, Puella Magi Madoka Magica
Harbinger
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 27
xx Re: FILES command tests
« Reply #2 on: Aug 29th, 2016, 1:46pm »

Good info! So it looks like you have to use FILES in multiple passes using the filter parameter to weed out these hidden files... undecided

Thanks that helps a lot... cool
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls