How to use "win32_find_data" in C# or VB.net?
-
Initially, I want to fetch or get a file from another machine either through local net or network share, and "win32_find_data" seems to be a good package for this task. But if I want to use it in C# or VB.NET, how should I do it? Or is there any other package I can use? Thanks a lot!
-
Initially, I want to fetch or get a file from another machine either through local net or network share, and "win32_find_data" seems to be a good package for this task. But if I want to use it in C# or VB.NET, how should I do it? Or is there any other package I can use? Thanks a lot!
Hi You will need to define 2 structures in C# first namely, FILETIME and WIN32_FIND_DATA. As:
struct FILETIME {
int dwLowDateTime;
int dwHighDateTime;
}struct WIN32_FIND_DATA {
int dwFileAttributes;
FILETIME ftCreationTime;
FILETIME ftLastAccessTime;
FILETIME ftLastWriteTime;
int nFileSizeHigh;
int nFileSizeLow;
int dwReserved0;
int dwReserved1;
string cFileName; //mite need marshalling, TCHAR size = MAX_PATH???
string cAlternateFileName; //mite need marshalling, TCHAR size = 14
}[DllImport("kernel32.dll")]
static extern IntPtr FindFirstFile( IntPtr lpfilename, ref WIN32_FIND_DATA findfiledata);[DllImport("kernel32.dll")]
static extern IntPtr FindClose( IntPtr pff);public static WIN32_FIND_DATA FindFile(string filename)
{
WIN32_FIND_DATA fd;
IntPtr pff = FindFirstFile(Marshal.StringToHGlobalAuto(filename), ref fd);
if (ppf == IntPtr.Zero) throw new FileNotFoundException();
FindClose(ppf);
return fd;
}Thats should do it, didnt check. Perhaps the TCHAR in the structs, but this should set u well on your way. Obviously, you can Add the other FindFile functions as well. Maybe there is something in .Net doing the same already??? :) MYrc : A .NET IRC client with C# Plugin Capabilities. See http://sourceforge.net/projects/myrc for more info. :-D
-
Initially, I want to fetch or get a file from another machine either through local net or network share, and "win32_find_data" seems to be a good package for this task. But if I want to use it in C# or VB.NET, how should I do it? Or is there any other package I can use? Thanks a lot!
HAHA :-O There is an example on MSDN doing exactly what you need. Pretty much the same as above. :) Look here, direct MSDN link, sorry dont have weblink, but should be easy to find. FindFile Sample [C#][^] Enjoy :) MYrc : A .NET IRC client with C# Plugin Capabilities. See http://sourceforge.net/projects/myrc for more info. :-D
-
Initially, I want to fetch or get a file from another machine either through local net or network share, and "win32_find_data" seems to be a good package for this task. But if I want to use it in C# or VB.NET, how should I do it? Or is there any other package I can use? Thanks a lot!
And finally the .NET way....jeez i'm bored today :) Directory.GetFileSystemEntries Method Returns the names of all files and subdirectories in the specified directory. [Visual Basic] Overloads Public Shared Function GetFileSystemEntries(String) As String() [C#] public static string[] GetFileSystemEntries(string); Returns an array of file system entries matching the specified search criteria. [Visual Basic] Overloads Public Shared Function GetFileSystemEntries(String, String) As String() [C#] public static string[] GetFileSystemEntries(string, string); :) MYrc : A .NET IRC client with C# Plugin Capabilities. See http://sourceforge.net/projects/myrc for more info. :-D