473,387 Members | 1,541 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,387 software developers and data experts.

how to check if a directory exists / and create it if it doesn't

If (Directory.Exists(@"c:\indigo\" + txtOfficial + @"\" +
comOffice.Text + @"\" + numTerm.Value.ToString()))
{
storereport();
}
else

{
Directory.CreateDirectory(@"c:\indigo\" + txtOfficial +
@"\" + comOffice.Text + @"\" + numTerm.Value.ToString());
}

this isn't compiling, and else is being underlined as wrong. Any
suggestions on how to fix this please?

Nov 10 '06 #1
2 3928
if you change If to if it compiles fine for me. Keywords in c# are all lower
case

Ciaran O'Donnell

"CCLeasing" wrote:
If (Directory.Exists(@"c:\indigo\" + txtOfficial + @"\" +
comOffice.Text + @"\" + numTerm.Value.ToString()))
{
storereport();
}
else

{
Directory.CreateDirectory(@"c:\indigo\" + txtOfficial +
@"\" + comOffice.Text + @"\" + numTerm.Value.ToString());
}

this isn't compiling, and else is being underlined as wrong. Any
suggestions on how to fix this please?

Nov 10 '06 #2
It's probably worth mentioning that everything is case sensitive in C#.
Second, as you have two idential strings it's worth putting them in a
variable otherwise you may forget to change one.

string dirpath = @"c:\indigo\" + txtOfficial + @"\" + comOffice.Text +
@"\" + numTerm.Value.ToString();
if (Directory.Exists(dirpath))
{
storereport();
}
else
{
Directory.CreateDirectory(dirpath);
}
Finally, there's a logic error in your code. If the directory exists it
saves the report, if it doesn't it just creates the directory and
doesn't store it. Is this more what you want?
if (!Directory.Exists(@"c:\indigo\" + txtOfficial + @"\" +
comOffice.Text + @"\" + numTerm.Value.ToString()))
{
Directory.CreateDirectory(dirpath);
}
storereport();

Finally StoreReport (methods should have capital first letters for each
word) probably also builds that path string, so perhaps make it a
member variable of the class?

Ciaran O''Donnell wrote:
if you change If to if it compiles fine for me. Keywords in c# are all lower
case

Ciaran O'Donnell

"CCLeasing" wrote:
If (Directory.Exists(@"c:\indigo\" + txtOfficial + @"\" +
comOffice.Text + @"\" + numTerm.Value.ToString()))
{
storereport();
}
else

{
Directory.CreateDirectory(@"c:\indigo\" + txtOfficial +
@"\" + comOffice.Text + @"\" + numTerm.Value.ToString());
}

this isn't compiling, and else is being underlined as wrong. Any
suggestions on how to fix this please?
Nov 10 '06 #3

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

Similar topics

3
by: Russell E. Owen | last post by:
I stumbled across a really strange bug involving directories on linux. os.path.exists(path) can return 0 even after os.path.mkdir(path) succeeds (well after; this isn't a timing issue). For...
2
by: Jonathan | last post by:
I am looking for a simple way to check if a database table exists. I keep getting advice to use "Try.. Catch" and other error handling methods, but I obviously don't want to have to display an...
9
by: Sheldon Cohen | last post by:
Hello, I am using c# and running a site that is on a shared host. The code in question is supposed to create a new directory that is coming out of a text box. It works fine on my computer, but...
6
by: Sigmathaar | last post by:
Hi, while making an XML parser for the creation of an entire directory list I got this problem and I'm having trouble solving it. The program (not yet written) goes through an XML Schema Instance...
1
by: Phil Barber | last post by:
using ASP.NET 1.1 int PID=(int)Session; string FilePath=PF.GetProjectPath(PID); if(!Directory.Exists(FilePath)) Directory.CreateDirectory(FilePath); the Directory.Exists always returns false...
9
by: Martin Jørgensen | last post by:
Hi, I guess in every beginners C-book it writes about how to declare a filepointer fp and how to create a file (at least in mine)...... Like here: FILE * fp; fp = fopen("output_file.txt",...
1
by: sudhapadmas | last post by:
Hello netters, I was trying to create a virtual directory in IIS using the following code: System.EnterpriseServices.Internal.IISVirtualRoot vr = new...
12
by: samoore33 | last post by:
I found a real nice article on how to copy a directory on MSDN. The only problem is that I can not figure out how to get the namespace Microsoft.VisualBasic.MyServices. I wanted to know if anyone...
14
by: John Salerno | last post by:
What is the best way to check if a file already exists in the current directory? I saw os.path.isfile(), but I'm not sure if that does more than what I need. I just want to check if a file of a...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...

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.