drives files and folders
Posted: Sat Sep 15, 2012 3:30 am
There are three things that every person that programs has to get into sooner or
later, and they are tied together. That is drives, folders, and files. Now many
books on programming only get as far as the file stage. A few might get into
the current folder as well. It is a very few that go beyond that point.
Let's start off with drives first. Following long established protocols, when dealing
with DOS or Windows, drives are assigned a letter of identification from the 26
letters in the alphabet. Early PCs only had floppy drives, and the letters "A" and
"B" were reserved for them, since the idea was to just have one or two floppy
drives per PC. That seemed more than adequate at the time.
The first large drives where given the letter "C"., and if a second was installed,
it was given the letter "D". Note that capital letters and lower case letters all
address the same drive, so "C" is the same as "c" and "D" is the same as "d".
When CD drives came along, and later the DVD and DVD/CD drives, they also got
a single letter identifier. PCs fell into a new configuration, of one floppy drive
(the "A" drive), one hard drive (the "C" drive), and one CD or DVD/CD drive (the
"D" drive). Some PCs came out with a "hidden" D Drive, which held a backup of
all the software that came initially installed on the PC when it was sold as new.
Hard drives got bigger at a fast rate, This created problems with existing
software being able to access a whole drive. What they did was divide a large
hard drive into logical drives, each one seeming to be a separate hard drive to
the system. Each one correspondingly got its own drive letter. Because of the
conventions followed, a hard drive could be divided into four logical drives. To
go beyond this limit later on, one logical drive was earmarked to be an extended
logical drive, and it could be divided in additional logical drives. But while the
drives growing in how much data they could hold, they were shrinking in size
and the system software was catching up with handling larger capacity drives.
What you have now is hardly any floppy drives, the drive letters "A" and "B'
unused as a consequent, a huge hard drive as your drive "C", your CD or
DVD/CD drive now the "D" and maybe the "E" drive if you have two, possibly
some networked drives that are each given a letter, and beyond that, it is
anyone's guess. The owner of the PC should know what he or she has, but
how about writing software that works with as few or as many drives as there
actually are?
Okay =, so you have drives to deal with, and to do that, you want your software
to be able to check out the ones that are there. And here is a program that
shows you several ways of doing that using PureBasic:
Now I mentioned folders as well. When thinking of folders, think of those manila things
that fit in office cabinets. Cabinets come in different sizes with different number of
drawers in them, going back different depths. The cabinets are like the hard drives
discussed earlier. Most anything can go into them. To keep it orderly, we put in
folders and arrange things in the folders and by folders, putting names to the folders
so that we know where we are. But when you are talking about folders, you are also
going to run into three other terms: subfolders, directories, and subdirectories.
So folders are also directories, right? Exactly. So what is a subfolder or a subdirectory?
It is a folder or directory that is linked back to a higher level folder or directory. It's
like looking at a tree, and seeing branches growing out of branches, and more
branches growing out of them in turn. Now that you have been shown how to get
around from tree to tree (meaning drive to drive), your next journey might be to
get from limb to limb as you work your way up a tree. Limbs in this case another
name for branches, like folders are another name for directories.
.
later, and they are tied together. That is drives, folders, and files. Now many
books on programming only get as far as the file stage. A few might get into
the current folder as well. It is a very few that go beyond that point.
Let's start off with drives first. Following long established protocols, when dealing
with DOS or Windows, drives are assigned a letter of identification from the 26
letters in the alphabet. Early PCs only had floppy drives, and the letters "A" and
"B" were reserved for them, since the idea was to just have one or two floppy
drives per PC. That seemed more than adequate at the time.
The first large drives where given the letter "C"., and if a second was installed,
it was given the letter "D". Note that capital letters and lower case letters all
address the same drive, so "C" is the same as "c" and "D" is the same as "d".
When CD drives came along, and later the DVD and DVD/CD drives, they also got
a single letter identifier. PCs fell into a new configuration, of one floppy drive
(the "A" drive), one hard drive (the "C" drive), and one CD or DVD/CD drive (the
"D" drive). Some PCs came out with a "hidden" D Drive, which held a backup of
all the software that came initially installed on the PC when it was sold as new.
Hard drives got bigger at a fast rate, This created problems with existing
software being able to access a whole drive. What they did was divide a large
hard drive into logical drives, each one seeming to be a separate hard drive to
the system. Each one correspondingly got its own drive letter. Because of the
conventions followed, a hard drive could be divided into four logical drives. To
go beyond this limit later on, one logical drive was earmarked to be an extended
logical drive, and it could be divided in additional logical drives. But while the
drives growing in how much data they could hold, they were shrinking in size
and the system software was catching up with handling larger capacity drives.
What you have now is hardly any floppy drives, the drive letters "A" and "B'
unused as a consequent, a huge hard drive as your drive "C", your CD or
DVD/CD drive now the "D" and maybe the "E" drive if you have two, possibly
some networked drives that are each given a letter, and beyond that, it is
anyone's guess. The owner of the PC should know what he or she has, but
how about writing software that works with as few or as many drives as there
actually are?
Okay =, so you have drives to deal with, and to do that, you want your software
to be able to check out the ones that are there. And here is a program that
shows you several ways of doing that using PureBasic:
Code: Select all
Procedure waitkey()
Print("Press a key to continue... ")
Repeat
Delay(25)
k$=Inkey()
If k$>""
Break
EndIf
ForEver
PrintN("")
EndProcedure
OpenConsole() ; First we must open a console
ConsoleTitle ("What Drives Do I Have (Can I Use)")
EnableGraphicalConsole(1)
ConsoleColor(15,1)
ClearConsole()
PrintN("Here are four ways to identify the usable drives in a PC system.")
PrintN("MAXIMIZE your console screen to seem them all at work, one at a time.")
ConsoleLocate (0,3) ; x y position
PrintN("We try to access each drive in turn using ExamineDirectory()")
PrintN("")
For a.l=Asc("C") To Asc("Z")
b.l = ExamineDirectory(#PB_Any, Chr(a)+":\", "\")
If b
PrintN("Drive "+Chr(a)+": can be used.")
FinishDirectory(b)
EndIf
Next
waitkey()
PrintN("")
PrintN("Now we try to access each drive in turn using OpenFile()")
PrintN("")
For a.l=Asc("C") To Asc("Z")
b.l = OpenFile(#PB_Any, Chr(a)+":\nul")
If b
PrintN("Drive "+Chr(a)+": can be used.")
CloseFile(b)
EndIf
Next
waitkey()
PrintN("")
PrintN("Now we try to access each drive in turn using ReadFile()")
PrintN("")
For a.l=Asc("C") To Asc("Z")
b.l = ReadFile(#PB_Any, Chr(a)+":\nul")
If b
PrintN("Drive "+Chr(a)+": can be used.")
CloseFile(b)
EndIf
Next
PrintN("")
PrintN(" If you fail to see a drive, such as a CD drive or DVD/CD drive, it could be")
PrintN(" that it is not available, not ready or there is some other reason that it is")
PrintN(" not responding. The three checks above do not depend on whether the drive")
PrintN(" is Read Only or not. If you want to be sure that, the next check (and a")
PrintN(" valid file name rather than 'nul') should verify that it can be written to.")
PrintN("")
waitkey()
PrintN("")
PrintN("Now we try to access each drive in turn using CreateFile()")
PrintN("")
For a.l=Asc("C") To Asc("Z")
b.l = CreateFile(#PB_Any, Chr(a)+":\nul")
If b
PrintN("Drive "+Chr(a)+": can be used.")
CloseFile(b)
EndIf
Next
waitkey()
that fit in office cabinets. Cabinets come in different sizes with different number of
drawers in them, going back different depths. The cabinets are like the hard drives
discussed earlier. Most anything can go into them. To keep it orderly, we put in
folders and arrange things in the folders and by folders, putting names to the folders
so that we know where we are. But when you are talking about folders, you are also
going to run into three other terms: subfolders, directories, and subdirectories.
So folders are also directories, right? Exactly. So what is a subfolder or a subdirectory?
It is a folder or directory that is linked back to a higher level folder or directory. It's
like looking at a tree, and seeing branches growing out of branches, and more
branches growing out of them in turn. Now that you have been shown how to get
around from tree to tree (meaning drive to drive), your next journey might be to
get from limb to limb as you work your way up a tree. Limbs in this case another
name for branches, like folders are another name for directories.
.