|
Does anyone know where I can find an example of a function which recursively searches through a directory, and its subdirectories, for all files with a certain extension, and then returns an array of FileInfo objects for each of these files?
Mark Sanders
sanderssolutions.com
|
|
|
|
|
This is my search function:
public void FindDoc(string pathfile)
{
DirectoryInfo info = new DirectoryInfo(pathfile);
foreach (FileInfo f in info.GetFiles())
{
find(f);
}
foreach (DirectoryInfo d in info.GetDirectories())
{
foreach (FileInfo f in d.GetFiles())
{
find( f );
}
FindDoc(d.FullName);
}
}
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
find(f)? where is that defined?
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
|
Sorry it has a litlle problem.It search each file tow times.Here is correct form from MSDN:
public void FindDoc(string pathfile)
{
foreach (string d in Directory.GetDirectories(pathfile))
{
foreach (string f in Directory.GetFiles(d))
{
FileInfo info = new FileInfo(f);
find(info);
}
FindDoc(d);
}
}
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
Here's my final code. Rather simple really Thanks for the help.
private void GetFiles(DirectoryInfo directory, string searchPattern)
{
foreach(DirectoryInfo subdirectory in directory.GetDirectories())
GetFiles(subdirectory, searchPattern);
foreach(FileInfo file in directory.GetFiles(searchPattern))
fileList.Add(file);
}
Mark Sanders
sanderssolutions.com
|
|
|
|
|
How to validate user credentials (SSPI)on winNt, win2000,winXp, and without act as part of operating system privilege.
Example
Bool fctCheckUser(user,password,domain);
Return:
True is validate, false is not validate
I implented that but it don'work under windows xp..
[DllImport("Advapi32.dll")]
public static extern long LogonUser(string lpszUserName,string lpszDomain,string lpszPassword,long dwLogonType,long dwLogonProvider,long phToken);
const long LOGON32_PROVIDER_DEFAULT= 3;
const long LOGON32_LOGON_NETWORK= 0;
public Form1()
{
long ret = LogonUser("ll2","ww_europe","zoaqsdfzsol7",LOGON32_LOGON_NETWORK,LOGON32_PROVIDER_DEFAULT,ht);
MessageBox.Show(ret.ToString(), "test",MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
-=zoltx=-
|
|
|
|
|
The C++ DWORD type is equivalent to the .NET Int32 type, which is int in C#.
using System;
using System.Runtime.InteropServices;
public class WindowsLogon
{
public enum LogonType
{
Batch = 4,
Interactive = 2,
Network = 3,
NetworkCleartext = 8,
NewCredentials = 9,
Service = 5,
Unlock = 7,
}
public enum LogonProvider
{
Default = 0,
WinNT35 = 1,
WinNT40 = 2,
WinNT50 = 3,
}
[DllImport("Advapi32.dll")]
private static extern bool LogonUser(
string lpszUserName,
string lpszDomain,
string lpszPassword,
LogonType dwLogonType,
LogonProvider dwLogonProvider,
out IntPtr phToken);
public static IntPtr LogonUser(
string username, string password, string domain)
{
return LogonUser(username, password, domain,
LogonType.Network, LogonProvider.Default);
}
public static IntPtr LogonUser(
string username, string password, string domain,
LogonType logonType, LogonProvider provider)
{
IntPtr ret = IntPtr.Zero;
if (LogonUser(
username, domain, password,
logonType, provider, out ret))
{
return ret;
}
else
return IntPtr.Zero;
}
static void Main()
{
try
{
Console.Write("Username: ");
string user = Console.ReadLine();
Console.Write("Password: ");
string password = Console.ReadLine();
string domain = Environment.GetEnvironmentVariable("USERDOMAIN");
Console.WriteLine("Domain: {0}", domain);
IntPtr token = LogonUser(user, password, domain);
if (IntPtr.Zero == token)
Console.WriteLine("Logon failed!");
else
Console.WriteLine("Logon OK!");
}
catch(Exception ex)
{
Console.WriteLine(ex);
}
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
Is there any way to create UserControls in a different AppDomain of the owner form ? How can I isolate a UserControl created dynamically (for security and loading reasons)?
thanks
|
|
|
|
|
Is there any way to get a deployment project in Visual Studio.NET to give you a summary of what files it is including and, much more importantly, where it retrieved the files? I'll take anything, including VS Macros, command line, etc.
John Woodard
|
|
|
|
|
Hi guys,
Can you suggest me some ways or component to read an entire chunk of file and convert between ASCII and EBCDIC and save it back as a new file.
I got some code in fastheadcafe, but it deals with strings. But I do not know, in which format, StreamReaders or something else should be specified (Encoding Options??) so that it identifies the format and converts to the desired format.
A code example would be great!!!
Thanks and Regards,
Deepak Kumar Vasudevan
Deepak Kumar Vasudevan
http://deepak.portland.co.uk/
|
|
|
|
|
Is CodeParser Class Implemented?
Vikram
|
|
|
|
|
No. (at least in .NET 1.0)
|
|
|
|
|
how can i tell the .Net Framework to run agenst the newest version (as aposed to older versions) at application level with code ?. i ask that because the cast that i do (from a embed resouce) to a Image is invalid in earlyer versions but works fine in the newest version. Please let me know about ways acomplish this ...
Jesse M
The Code Project Is Your Friend...
|
|
|
|
|
|
thanks alot....but it appears since i dont have vs.net 2002 (i have sharp develop) i cant make a configuration file =(......what do i do then ?
Jesse M
The Code Project Is Your Friend...
|
|
|
|
|
jtmtv18 wrote:
i cant make a configuration file
The config file is a xml file!!! Just copy and past from that page and call the file <yourassemblyincludingextension>.config
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
do i embed it as a resource leppie ? or just include it with the distrubution ?(exscuse my spelling...lol)
Jesse M
|
|
|
|
|
Just make sure the file is in the same direxctory to be safe. I assume anywhere in the path should be ok...
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
I have an Icon .It has a member Save .According to MSDN I can save an Icon to a file with this function.Can anybody tell me how can I do it?
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
Try something like:
using System.IO;
...
void SaveToFile(Icon icon, string filename)
{
using(FileStream stream = File.Open(filename,
FileMode.OpenOrCreate,
FileAccess.Write,
FileShare.None))
{
icon.Save(stream);
stream.Flush();
stream.Close();
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
Thanks.
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
I keep getting this kind of errors when i run my program :
An unhandled exception of type 'System.Security.SecurityException' occurred in mscorlib.dll
Additional information: Request for the permission of type System.Net.SocketPermission, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.
Which occurs when i click on the listen button to start listening for incoming async connections. If i compile the EXE, use the .net Wizards "Trust an Assembly" and set the permissions to full, it works fine. But everytime i change some code, i have to do the same thing again (as in go to the wizard, trust an assembly...bla bla bla...is there a workaround to this nuisance?
I didn't have to do this at home, but sometimes i might need to do my work at college and it can be irritating having to set the permissions everytime i change something in the code because the assembly/public key would be different everytime something changes in the code.
|
|
|
|
|
Looking to find information on how to create a namespace extension in C# so that an icon shows up in the tree view of windows explorer and then build on it to show and perform certain function in the folder view.
|
|
|
|
|