|
say you pick one files in the openfiledialogue window. how can u get all the files names in a string array?
|
|
|
|
|
using System;
using System.IO;
using System.Collections;
// Takes an array of file names or directory names on the command line.
// Determines what kind of name it is and processes it appropriately
public class RecursiveFileProcessor {
public static void Main(string[] args) {
foreach(string path in args) {
if(File.Exists(path)) {
// This path is a file
ProcessFile(path);
}
else if(Directory.Exists(path)) {
// This path is a directory
ProcessDirectory(path);
}
else {
Console.WriteLine("{0} is not a valid file or directory.", path);
}
}
}
// Process all files in the directory passed in, and recurse on any directories
// that are found to process the files they contain
public static void ProcessDirectory(string targetDirectory) {
// Process the list of files found in the directory
string [] fileEntries = Directory.GetFiles(targetDirectory);
foreach(string fileName in fileEntries)
ProcessFile(fileName);
// Recurse into subdirectories of this directory
string [] subdirectoryEntries = Directory.GetDirectories(targetDirectory);
foreach(string subdirectory in subdirectoryEntries)
ProcessDirectory(subdirectory);
}
// Real logic for processing found files would go here.
public static void ProcessFile(string path) {
Console.WriteLine("Processed file '{0}'.", path);
}
}
This program will allow you to select all the files and subdirectory
once you pass the folder name
Paresh
|
|
|
|
|
you could find your solutions also at
http://www.gotdotnet.com/Community/MessageBoard/MessageBoard.aspx?ID=6
thanx
Paresh;P
|
|
|
|
|
Is there anything like isnumber("1")=true?
or something else?
thanks
|
|
|
|
|
string s = "1";
int n = Convert.ToInt32(s);
Paresh
|
|
|
|
|
however,
string s="a";
int n=Convert.toint32(s);
will give an error, won't it? there must be a way to tell...
|
|
|
|
|
|
if you want comparision
then
string s = "1";
if (s.CompareTo("1") == 0 )
{
// blah
}
Paresh
|
|
|
|
|
i found a discussion here:
http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_20391710.html
but i really can't believe this language leads to such a pain in the a$$
|
|
|
|
|
see, i just gave u the temp. working solution. i believe there are tons of solution for this type of problem
u could check char.by char.,
regex, string - try-catch method, int.parse, etc...
Paresh
|
|
|
|
|
Use this:
public static bool IsNumber(string strNumber)
{
Regex objNotNumberPattern=new Regex("[^0-9.-]");
Regex objTwoDotPattern=new Regex("[0-9]*[.][0-9]*[.][0-9]*");
Regex objTwoMinusPattern=new Regex("[0-9]*[-][0-9]*[-][0-9]*");
String strValidRealPattern="^([-]|[.]|[-.]|[0-9])[0-9]*[.]*[0-9]+$";
String strValidIntegerPattern="^([-]|[0-9])[0-9]*$";
Regex objNumberPattern =new Regex("(" + strValidRealPattern +")|(" + strValidIntegerPattern + ")");
return !objNotNumberPattern.IsMatch(strNumber) &&
!objTwoDotPattern.IsMatch(strNumber) &&
!objTwoMinusPattern.IsMatch(strNumber) &&
objNumberPattern.IsMatch(strNumber);
}
Deepak Kumar Vasudevan
http://deepak.portland.co.uk/
|
|
|
|
|
If this was VB.NET, you could use IsNumeric, so you could wrap that up in a class that is callable from C#.
Another C# approach would probably be to check each character in the string with IsDigit or IsNumber, or maybe use something similar to the following.
string s="1234";<br />
bool b = s.Trim("1234567890".ToCharArray()).Equals("");
--
Ian Darling
|
|
|
|
|
Here's the C# equivalent of VBs IsNumeric function:
using System;
using System.Globalization;
public class Conversion
{
private static bool IsNumericTypeCode(TypeCode t)
{
switch (t)
{
case TypeCode.Boolean:
case TypeCode.Byte:
case TypeCode.SByte:
case TypeCode.Int16:
case TypeCode.UInt16:
case TypeCode.Int32:
case TypeCode.UInt32:
case TypeCode.Int64:
case TypeCode.UInt64:
case TypeCode.Single:
case TypeCode.Double:
case TypeCode.Decimal:
return true;
default:
return false;
}
}
public static bool IsNumeric(object expression)
{
string sExp = null;
IConvertible conv = expression as IConvertible;
if (null == conv)
{
if (null == expression as char[])
return false;
sExp = new string((char[])expression);
}
else
{
TypeCode t = conv.GetTypeCode();
if (IsNumericTypeCode(t))
return true;
else if (t == TypeCode.String || t == TypeCode.Char)
sExp = conv.ToString(null);
}
if (null == sExp)
return false;
else
return IsNumeric(sExp);
}
public static bool IsNumeric(string expression)
{
if (null == expression || 0 == expression.Length)
return false;
else
{
double d;
return double.TryParse(expression,
NumberStyles.Any, null, out d);
}
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
That's cool function, Richard!!!
But wait!! I have one doubt... Sometimes C# Compiler shouts if I forget to put a break stating
'Control can not fall through...'
but here in this code snippet, you have said return true for multiple case options and it has compiled.
How?
Deepak Kumar Vasudevan
http://deepak.portland.co.uk/
|
|
|
|
|
The C# compiler is able to determine that any code after the return statement is unreachable, so execution could never fall through. If you add the break statements after the return statements, you'll see unreachable code warnings when you compile.
From the C# language reference:
The statement list of a switch section typically ends in a break, goto case, or goto default statement, but any construct that renders the end point of the statement list unreachable is permitted. For example, a while statement controlled by the Boolean expression true is known to never reach its end point. Likewise, a throw or return statement always transfers control elsewhere and never reaches its end point.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
Hi Richard,
Pl. see here:
switch (x)
{
case 1:
x =4;
break;
case 2:
case 3:
x = 5;
break;
default:
Console.Write("dog");
}
The compiler reports
C:\deepak\test.cs(31): Control cannot fall through from one case label ('default:') to another
What is the actual cause?
Deepak Kumar Vasudevan
http://deepak.portland.co.uk/
|
|
|
|
|
The end-point of your default case is reachable, since it doesn't end with a jump statement (break, return, goto, etc.)
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
Does anybody know how to show the childs as tabbed documents in an MDI application?
Thanks
|
|
|
|
|
|
Hi,
Does anybody know how to make a MDI child dock (or a control from a windows control library) and slide like the toolbox?
Thanks
|
|
|
|
|
|
Newbie Simple question, I can change a textbox ForeColor, BackColor so that say the text is Blue,
But how do I do the same to the datetimepicker?
Although the properties are hidden, they can be changed but they make no difference to the form.
Thanks
Steve Graham
|
|
|
|
|
Are there "set" properties for the DateTimePicker ? If not, I don't think it's going to work.
R.Bischoff | C++
.NET, Kommst du mit?
|
|
|
|
|
I need to build a user control base class for a very large application. I must build a User Control base class, so it can be reused in embedded HTML pages and in .NET Win Forms. I need a set of common classes that will house common functionality for the application (e.g. securityUtilities, xmlUtilities, errorUtilities). Can anyone tell me a good method of doing this?
I have run into a few problems:
1) I can't do multiple inheritances in C#.
2) A user control can't be an abstract class.
3) I have considered building interfaces to combine the classes, but I don't need each class to be a static class.
Can anyone help?
Thank you,
Shane
|
|
|
|
|
C# does not support multiple inheritance. You can simulate this through interface inheritance.
R.Bischoff | C++
.NET, Kommst du mit?
|
|
|
|