Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to use "win32_find_data" in C# or VB.net?

How to use "win32_find_data" in C# or VB.net?

Scheduled Pinned Locked Moved C#
csharpsysadmintutorialquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Segal
    wrote on last edited by
    #1

    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!

    L 3 Replies Last reply
    0
    • S Segal

      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!

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • S Segal

        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!

        L Offline
        L Offline
        leppie
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • S Segal

          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!

          L Offline
          L Offline
          leppie
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups