English 中文(简体)
获取文件位置:网络或本地
原标题:Getting location of a file: network or local

在Windows中,最容易找到文件位置的方法是什么?

我有一个文件名,它是通过Windows函数“ GetModuleName”返回给我的(返回模块(exe或dll)的完整名称),并且它可以是任何有效的文件名格式,例如:

  • myfile.dll
  • c:windowsmyfile.dll
  • ?c:windowsmyfile.dll (or something like this)
  • x:inmyfile.dll
  • myservermysharemyfile.dll

最简单的方法是如何知道路径是指本地驱动器还是网络驱动器?

最佳回答

GetFullPathName() 将帮助规范化路径名。虽然我认为你不需要它。你想要通过句柄进行调用。因此,调用 CreateFile(),获取句柄, 然后调用 GetFinalPathNameByHandle(VOLUME_NAME_GUID)。这可以工作,因为网络驱动器没有卷GUID。

问题回答

这段代码可能对您有帮助,它可以确定文件夹是否在网络共享上。

#include <windows.h>
#include <stdio.h>
#include <lm.h>

int main()
{
   PSHARE_INFO_502 BufPtr, p;
   NET_API_STATUS res;
   LPTSTR   lpszServer = NULL;
   DWORD er = 0,tr = 0,resume = 0, i;

   do
   {
      res = NetShareEnum(lpszServer, 502, (LPBYTE *) &BufPtr, -1, &er, &tr, &resume);

      if(res == ERROR_SUCCESS || res == ERROR_MORE_DATA)
      {
         p = BufPtr;

         for(i = 1; i <= er; i++)
         {
             printf("%S		%S
", p->shi502_netname, p->shi502_path);
             p++;
         }

         NetApiBufferFree(BufPtr);
      }
      else 
         printf("Error: %ld
", res);
   }
   while(res == ERROR_MORE_DATA);

   system("pause");
   return 0;
}




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签