473,830 Members | 2,174 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DirectoryInfo

Suppose I have the following code:

<script runat="server">
Sub Page_Load(..... )
Dim dInfo As DirectoryInfo
Dim fsi As FileSystemInfo

dInfo = New DirectoryInfo(S erver.MapPath(" Folder1"))

For Each fsi In dInfo.FileSyste mInfo
If (fsi.GetType Is GetType(Directo ryInfo)) Then
Response.Write( fsi.Name & " <DIR><br>")
Else
Response.Write( fsi.Name & "<FILE><br> "
End If
Next
End Sub
</script>

Assume that the folder named 'Folder1' has only 1 directory & 10 files.
When the above code is executed, then items which are directories get
successfully appended with <DIRwhereas items which are files get
appended with <FILE>. No problems till here.

But if I replace the If condition shown above (the first line within
the For..Next loop) with the following If conditiom:

If (fsi.GetType Is GetType(Directo ry))

i.e. change the second operand from GetType(Directo ryInfo) to
GetType(Directo ry), then even the single directory existing in Folder1
gets appended with <FILE& not with <DIR>.

Why so?

Jan 7 '07 #1
2 2188
The answer is the FileSystemInfo class is a base for the DirectoryInfo and
FileInfo classes. It categorizes a directory as a DirectoryInfo and not a
Directory. So, since the directory is actually of type DirectoryInfo, then
it will assume it's not a directory and get the <fileappended to it.
--

Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006
<rn**@rediffmai l.comwrote in message
news:11******** **************@ s80g2000cwa.goo glegroups.com.. .
Suppose I have the following code:

<script runat="server">
Sub Page_Load(..... )
Dim dInfo As DirectoryInfo
Dim fsi As FileSystemInfo

dInfo = New DirectoryInfo(S erver.MapPath(" Folder1"))

For Each fsi In dInfo.FileSyste mInfo
If (fsi.GetType Is GetType(Directo ryInfo)) Then
Response.Write( fsi.Name & " <DIR><br>")
Else
Response.Write( fsi.Name & "<FILE><br> "
End If
Next
End Sub
</script>

Assume that the folder named 'Folder1' has only 1 directory & 10 files.
When the above code is executed, then items which are directories get
successfully appended with <DIRwhereas items which are files get
appended with <FILE>. No problems till here.

But if I replace the If condition shown above (the first line within
the For..Next loop) with the following If conditiom:

If (fsi.GetType Is GetType(Directo ry))

i.e. change the second operand from GetType(Directo ryInfo) to
GetType(Directo ry), then even the single directory existing in Folder1
gets appended with <FILE& not with <DIR>.

Why so?

Jan 8 '07 #2
Mark, to some extent, I could understand what you have said.

Now you are saying that since the directory is actually of type
DirectoryInfo, it will assume it's not a directory & hence get <FILE>
appended to it. But since the directory is actually of type
DirectoryInfo, then why doesn't it assume that it's a DirectoryInfo
instead of assuming that it's not a directory?

Could you please explain me this point? Getting a bit confused....to be
honest...

Moreover, like the FileSystemInfo class is the base class for the
DirectoryInfo & FileInfo classes, which class is the base class for the
Directory & File classes?

Thanks
Mark Fitzpatrick wrote:
The answer is the FileSystemInfo class is a base for the DirectoryInfo and
FileInfo classes. It categorizes a directory as a DirectoryInfo and not a
Directory. So, since the directory is actually of type DirectoryInfo, then
it will assume it's not a directory and get the <fileappended to it.
--

Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006
<rn**@rediffmai l.comwrote in message
news:11******** **************@ s80g2000cwa.goo glegroups.com.. .
Suppose I have the following code:

<script runat="server">
Sub Page_Load(..... )
Dim dInfo As DirectoryInfo
Dim fsi As FileSystemInfo

dInfo = New DirectoryInfo(S erver.MapPath(" Folder1"))

For Each fsi In dInfo.FileSyste mInfo
If (fsi.GetType Is GetType(Directo ryInfo)) Then
Response.Write( fsi.Name & " <DIR><br>")
Else
Response.Write( fsi.Name & "<FILE><br> "
End If
Next
End Sub
</script>

Assume that the folder named 'Folder1' has only 1 directory & 10 files.
When the above code is executed, then items which are directories get
successfully appended with <DIRwhereas items which are files get
appended with <FILE>. No problems till here.

But if I replace the If condition shown above (the first line within
the For..Next loop) with the following If conditiom:

If (fsi.GetType Is GetType(Directo ry))

i.e. change the second operand from GetType(Directo ryInfo) to
GetType(Directo ry), then even the single directory existing in Folder1
gets appended with <FILE& not with <DIR>.

Why so?
Jan 8 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1378
by: Andy | last post by:
I am trying to use the DirectoryInfo class to create links on a web page to files in the specified directory. I can get it to work just fine. The problem I am having is when I try to put in a UNC path, it does not work. It says it cannot find the specified path. Below is the code I am using Dim dirInfo as New DirectoryInfo("\\ServerName\Directory\SubDirectory") I can only get this to work when I use local directories such as "D:\" ...
4
4709
by: Pluto | last post by:
Hi, I want to get a list of files matching certain extensions, such as "*.jpg;*.gif" (i.e. all files ending with .jpg and .gif). I was using DirectoryInfo.GetFiles(string) method. Unfortunately it appears that I cannot have something like: dirInfo.GetFiles("*.jpg;*.gif"); // where dirInfo is of type DirectoryInfo
1
2615
by: Vagabond Software | last post by:
I am recursing through ALL folders and sub-folders below a certain level to list all the files of a certain type in those folders. I use two ArrayLists, alFiles and alFolders, to track matching files and my progress in the recursion. I use a while loop to manage the folder-subfolder drill-down. Each pass through the while loop creates a new DirectoryInfo object named currentFolder. Is there are problem with that? Does this create...
1
10534
by: siddharth_jain_1 | last post by:
Hello I am trying to get a list of shared files and subdirectories in a particular folder on a server. For this I am using DirectoryInfo in the following way. DirectoryInfo folder = new DirectoryInfo("\\\\server_name\\shared_folder_name"); FileInfo fiArr = folder.GetFiles();
8
1902
by: Lyners | last post by:
I have code that retrieves all of the file names within a directory. After retriving them, I display the information in a datagrid. What I would like to do is add an extra output column on the directory info that would contain the file name without the extension. Can I add an attribute or an entry to accomplish this? If so, how, if not, is there anything I can do to do this. Here is my code that i am using; Dim dirInfo as New...
3
2401
by: xenophon | last post by:
This following innocuous code: System.IO.DirectoryInfo fff = new System.IO.DirectoryInfo(); System.IO.FileInfo ppp = fff.GetFiles( Request.MapPath(".") ); for( int ccc=0 ; ccc < ppp.Length ; ccc++ ) { System.Web.HttpResponse.Response.Write( "<a href=\"" + Request.MapPath(".") + "/" + HttpUtility.HtmlEncode(ppp.Name) + "\">link</a>" );
0
1967
by: MP | last post by:
Hi, I am getting the Access denied Error on a folder after I try to delete a folder that contains some files through my ASP.NET Application. Following is my code DirectoryInfo directoryInfo = new DirectoryInfo(EmailConfiguration.EmailImagesFolderRootPath + "\\Event_" + eventId);
3
3093
by: Steve Kershaw | last post by:
Hi, I need a way to bind a DirectoryInfo array to a GridView without any errors. The code I'm using to create the DirectoryInfo array is: // Define the current directory DirectoryInfo dir = new DirectoryInfo("C:\\Temp\\");
5
6148
by: Tom P. | last post by:
I am having the following problem: I create a FileSystemWatcher and wait for events. When the event does happen I refresh a FileSystemInfo list and set properties accordingly (IsFile, IsDir, ReadOnly, etc.). The problem I'm having is in identifying when a FileSystemInfo entry is a FileInfo or a DirectoryInfo type. I get the rare, and yet oddly common, "setup.inf" file that for some inexplicable reason passes the standard...
0
9791
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10771
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10487
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10525
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10202
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7745
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5780
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4411
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3958
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.