fopen文件从windows网络位置 [英] fopen file from windows network location

查看:130
本文介绍了fopen文件从windows网络位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以从已挂载的网络驱动器打开文件,但不能从卸载的文件夹中打开。例如\\mycomp\folder2\hi.bmp

I can open files from a mounted network drive, but not from an unmounted one e.g \\mycomp\folder2\hi.bmp

推荐答案

以下代码段适用于我:

char buffer[1000];    
FILE* file;
size_t bytesRead;

file = fopen("\\\\server\\share\\test.dat", "rb");  
if (file != NULL)
{
    bytesRead = fread(buffer, sizeof(char), sizeof(buffer), file);
    fclose(file);
}

另请注意 fopen docs(MSDN)


...

fopen将接受

文件系统上有效的路径的执行; 包含映射网络驱动器的UNC路径和路径
只要$ f
被fopen接受,只要执行代码的
系统已访问共享或映射网络
在执行时驱动
。在构建路径时必须特别注意
为fopen使用
,以避免在执行
环境中对可用驱动器,路径或
网络共享做出假设


...

fopen will accept paths that are valid on the file system at the point of execution; UNC paths and paths involving mapped network drives are accepted by fopen as long as the system executing the code has access to the share or mapped network drive at the time of execution. Special care must be taken when constructing paths for fopen to avoid making assumptions about available drives, paths or network shares in the execution environment.
...

您还需要考虑,程序下,需要具有适当的访问权限到文件。当您将共享作为网络驱动器安装时,也许您正在使用不同的凭据来连接。这可能会导致 fopen 失败。

You also need to consider, that the account you are running your program under, needs to have the appropriate access rigths to the file. When you mount the share as a network drive, maybe you are using different credentials to connect. That could cause fopen to fail.

这篇关于fopen文件从windows网络位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆