win32api oldefoxx
Posted: Sat Sep 22, 2012 5:41 am
As I've mentioned elsewhere, I am in the process of moving to PureBasic after HotBasic
bombed out on me. I try to go easy on what I say about HotBasic because it may still
suit some people, and it is not that hard to learn. But I would not say that it is worth
what is being charged for it. I also left PowerBasic behind years ago for other, although
somewhat similar reasons, though PowerBasic does measure up better.
Enough said on that. I wrote a routine in PureBasic that failed to deliver on the right
number of directories and files found per drive. To try and find the cause, I had to first
try and determine what the correct count should be. So I went to the Windows APIs to
find a solution.
Now with the Windows APIs, there are several approaches, but they all boil down to
making use of the function APIs named FindFirstFile(), FindNextFile() FindClose() and
if you want to do it right, GetLastError(). There is lots of sample code out there, but
if you search the web, most of it involves C or C++. You have to visit specific forums
to find it in other languages.
But here is the thing: My PC is configured with Ubuntu as the host Operating System, on
which I run Oracle's VirtualBox, and under VirtualBox I have Windows 2000 installed as a
client. Win2k may be obsolete elsewhere, but I am fine with it. I just can't use Crome or
the latest versions of FireFox with it. But I can run those on the host side.
To make best use of my hard drives, I have them all connected to the Win2k client via
VirtualBox as shared folders. With the extended add-ins that Oracle provides, everything
works as it should. Except in one respect, which I just discovered: Using FindFirstFile()
and FindNextFile() in the APIs, all folders and files on the Linux drives are reported to be
folders. You have no files to look at. But Windows 2000 itself has no problem making the
distinction. In fact, at the Command Line you can use DIR and be able to recognize both
files and folders on those drives.
Well, that's not what I had in mind. Turns out I am going to have to use the following
command string to get the job done, folder by folder. Unfortunately, I can't show you the
string in PureBasic, because I don't know the equivalence to a SHELL command in PureBAsic.
SHELL "cmd /c dir "+path+" /l /-c > tmpfile.tmp"
Now when you use the above command (or the PureBasic equivalent), you don't get all the
folders and files. No, the associated attribut bits don't permit this. You have to shell multiple
times to get everything, and you will end up with duplicates that have to be weeded out
later, probably after an array sort is used to bunch all the identical ones together. Afte the
above statement, you really need to follow with these:
SHELL "cmd /c dir "+path+" /ad /l /-c >> tmpfile.tmp"
SHELL "cmd /c dir "+path+" /as /l /-c >> tmpfile.tmp"
SHELL "cmd /c dir "+path+" /ah /l /-c >> tmpfile.tmp"
SHELL "cmd /c dir "+path+" /ar /l /-c >> tmpfile.tmp"
That gets the directories, the system files, the hidden files, and the read only files as well.
If you include the " /s " switch as well, you will automatically tell the DIR instruction to range
through all the subdirecrories (subfolders) as well, but that ends up with a monster file that
you then have to wade through. With the added four DIR searches, that is a lot of sorting
to get through before you begin processing the results, so I recommend only doing one
directory (or folder) at a time. You can pick out the directory entries because they will say
"<DIR>" and the files leave that space blank.
Okay, so having paid my dues with some tips of my own, what is the PureBasic equivalent to
other Basics' SHELL statement?
bombed out on me. I try to go easy on what I say about HotBasic because it may still
suit some people, and it is not that hard to learn. But I would not say that it is worth
what is being charged for it. I also left PowerBasic behind years ago for other, although
somewhat similar reasons, though PowerBasic does measure up better.
Enough said on that. I wrote a routine in PureBasic that failed to deliver on the right
number of directories and files found per drive. To try and find the cause, I had to first
try and determine what the correct count should be. So I went to the Windows APIs to
find a solution.
Now with the Windows APIs, there are several approaches, but they all boil down to
making use of the function APIs named FindFirstFile(), FindNextFile() FindClose() and
if you want to do it right, GetLastError(). There is lots of sample code out there, but
if you search the web, most of it involves C or C++. You have to visit specific forums
to find it in other languages.
But here is the thing: My PC is configured with Ubuntu as the host Operating System, on
which I run Oracle's VirtualBox, and under VirtualBox I have Windows 2000 installed as a
client. Win2k may be obsolete elsewhere, but I am fine with it. I just can't use Crome or
the latest versions of FireFox with it. But I can run those on the host side.
To make best use of my hard drives, I have them all connected to the Win2k client via
VirtualBox as shared folders. With the extended add-ins that Oracle provides, everything
works as it should. Except in one respect, which I just discovered: Using FindFirstFile()
and FindNextFile() in the APIs, all folders and files on the Linux drives are reported to be
folders. You have no files to look at. But Windows 2000 itself has no problem making the
distinction. In fact, at the Command Line you can use DIR and be able to recognize both
files and folders on those drives.
Well, that's not what I had in mind. Turns out I am going to have to use the following
command string to get the job done, folder by folder. Unfortunately, I can't show you the
string in PureBasic, because I don't know the equivalence to a SHELL command in PureBAsic.
SHELL "cmd /c dir "+path+" /l /-c > tmpfile.tmp"
Now when you use the above command (or the PureBasic equivalent), you don't get all the
folders and files. No, the associated attribut bits don't permit this. You have to shell multiple
times to get everything, and you will end up with duplicates that have to be weeded out
later, probably after an array sort is used to bunch all the identical ones together. Afte the
above statement, you really need to follow with these:
SHELL "cmd /c dir "+path+" /ad /l /-c >> tmpfile.tmp"
SHELL "cmd /c dir "+path+" /as /l /-c >> tmpfile.tmp"
SHELL "cmd /c dir "+path+" /ah /l /-c >> tmpfile.tmp"
SHELL "cmd /c dir "+path+" /ar /l /-c >> tmpfile.tmp"
That gets the directories, the system files, the hidden files, and the read only files as well.
If you include the " /s " switch as well, you will automatically tell the DIR instruction to range
through all the subdirecrories (subfolders) as well, but that ends up with a monster file that
you then have to wade through. With the added four DIR searches, that is a lot of sorting
to get through before you begin processing the results, so I recommend only doing one
directory (or folder) at a time. You can pick out the directory entries because they will say
"<DIR>" and the files leave that space blank.
Okay, so having paid my dues with some tips of my own, what is the PureBasic equivalent to
other Basics' SHELL statement?