473,385 Members | 1,427 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

DirectoryExists on 1st 4 chars

We have a intranet web site that displays a hyperlink if the subfolder on
the network file system contains 1 or more physical files. The file system
is pointed to by a virtual directory on our web site. I am using the code
below to check for existing folder and if not found, create it. My problem
is that sometimes the subfolder name does not exactly match the name we are
looking for. However, if the 1st 4 characters are the same I want to
consider it a match (found directory) but I don't know how to do that. I
also want to use the GetFiles with that partial match to get the file count.
Can anyone help? Thanks.

David

If My.Computer.FileSystem.DirectoryExists(strPath) = False Then

My.Computer.FileSystem.CreateDirectory(strPath)

End If

If My.Computer.FileSystem.GetFiles(strPath).Count = 0 Then

varCtl = e.Row.FindControl("HLViewDocs")

varCtl.Text = ""

Else

e.Row.Cells(11).CssClass = "Show"

End If
Nov 16 '07 #1
2 904
Howdy,

Dim path As String = "c:\temp\myDir"
Dim directoryExists As Boolean = System.IO.Directory.Exists(path)

If Not directoryExists Then

Dim parentDirectory As String = _
System.IO.Path.GetDirectoryName(path)
Dim searchPattern As String = _
System.IO.Path.GetFileName(path).Substring(0, 4) & "*"

directoryExists = System.IO.Directory.GetDirectories( _
parentDirectory, _
searchPattern, _
System.IO.SearchOption.TopDirectoryOnly).Length 0

End If

If Not directoryExists Then
System.IO.Directory.CreateDirectory(path)
End If

Hope this helps
--
Milosz
"David C" wrote:
We have a intranet web site that displays a hyperlink if the subfolder on
the network file system contains 1 or more physical files. The file system
is pointed to by a virtual directory on our web site. I am using the code
below to check for existing folder and if not found, create it. My problem
is that sometimes the subfolder name does not exactly match the name we are
looking for. However, if the 1st 4 characters are the same I want to
consider it a match (found directory) but I don't know how to do that. I
also want to use the GetFiles with that partial match to get the file count.
Can anyone help? Thanks.

David

If My.Computer.FileSystem.DirectoryExists(strPath) = False Then

My.Computer.FileSystem.CreateDirectory(strPath)

End If

If My.Computer.FileSystem.GetFiles(strPath).Count = 0 Then

varCtl = e.Row.FindControl("HLViewDocs")

varCtl.Text = ""

Else

e.Row.Cells(11).CssClass = "Show"

End If
Nov 17 '07 #2
I'll give it a try. Thank you.
-David
"Milosz Skalecki [MCAD]" <mi*****@DONTLIKESPAMwp.plwrote in message
news:54**********************************@microsof t.com...
Howdy,

Dim path As String = "c:\temp\myDir"
Dim directoryExists As Boolean = System.IO.Directory.Exists(path)

If Not directoryExists Then

Dim parentDirectory As String = _
System.IO.Path.GetDirectoryName(path)
Dim searchPattern As String = _
System.IO.Path.GetFileName(path).Substring(0, 4) & "*"

directoryExists = System.IO.Directory.GetDirectories( _
parentDirectory, _
searchPattern, _
System.IO.SearchOption.TopDirectoryOnly).Length 0

End If

If Not directoryExists Then
System.IO.Directory.CreateDirectory(path)
End If

Hope this helps
--
Milosz
"David C" wrote:
>We have a intranet web site that displays a hyperlink if the subfolder on
the network file system contains 1 or more physical files. The file
system
is pointed to by a virtual directory on our web site. I am using the
code
below to check for existing folder and if not found, create it. My
problem
is that sometimes the subfolder name does not exactly match the name we
are
looking for. However, if the 1st 4 characters are the same I want to
consider it a match (found directory) but I don't know how to do that. I
also want to use the GetFiles with that partial match to get the file
count.
Can anyone help? Thanks.

David

If My.Computer.FileSystem.DirectoryExists(strPath) = False Then

My.Computer.FileSystem.CreateDirectory(strPath)

End If

If My.Computer.FileSystem.GetFiles(strPath).Count = 0 Then

varCtl = e.Row.FindControl("HLViewDocs")

varCtl.Text = ""

Else

e.Row.Cells(11).CssClass = "Show"

End If

Nov 19 '07 #3

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

Similar topics

8
by: Nick | last post by:
Hi ! I want to load an old Pascal-Dos-File where records stand in. When i view the file in a HEX-Editor it's clear how to acces these Strings and chars in that file. Since these are old 8BIT...
8
by: Nikolay Petrov | last post by:
I need a way to strip chars from a string. The chars are all chars that are not allowed in file path. TIA
6
by: guy | last post by:
if a string contains surrogate chars (i.e. Unicode characters that consiste of more than 1 char) do functions that use an indexer or a string length into the string e.g. Mid, Len work correctly? ...
7
by: Edward Elliott | last post by:
I'm looking for the "best" way to strip a large set of chars from a filename string (my definition of best usually means succinct and readable). I only want to allow alphanumeric chars, dashes,...
1
by: tomtiv | last post by:
Hi All, I am having a probem with asp, xml, com while using chinese chars. The chinese letters come out of com fine and they are also fine when i use asp to write to a text file. When i load...
9
by: kaustubh.deo | last post by:
I am facing issues printing french chars like using printf function. I have reproduced this issue with simple C program as follows. #include <stdio.h> #include <locale.h> int main(int...
0
by: Yobbo | last post by:
Hi All I have an ASP function in place to strip invalid chars out of a data store before I create an XML file of this data, but my function doesn't work on a certain set of chars. As far as I...
6
by: Christoph Zwerschke | last post by:
In Python programs, you will quite frequently find code like the following for removing a certain prefix from a string: if url.startswith('http://'): url = url Similarly for stripping...
13
by: Hongyu | last post by:
Hi, I have a datetime char string returned from ctime_r, and it is in the format like ""Wed Jun 30 21:49:08 1993\n\0", which has 26 chars including the last terminate char '\0', and i would...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.