使用 fopen 和 C 在 Windows 中打开长文件名 [英] Opening long file names in Windows using fopen with C

查看:36
本文介绍了使用 fopen 和 C 在 Windows 中打开长文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 fopen 打开路径超过 Windows 本机支持的 ​​260 个字符的文件时遇到问题.

I have trouble here using fopen to open files which have paths longer than the 260 characters supported by Windows natively.

我发现了前缀 \\\\?\\ 我需要把它放在路径前面才能处理文件.

I found out about the prefix \\\\?\\ which I need to put in front of the path to be able to handle the file.

我的问题是:这与 fopen 结合是否仍然有效?我仍然无法打开文件,但我找不到有关它的信息.我的路径如下:

My question is: Is this still valid in combination with fopen? I have still trouble to open the files, but I do not find information about it. My paths look like:

\\\\?\\C:\\Deposit\\Source\\Here_Comes_Now_A_List_Of_Many_Subdirs_And_A_Long_File_Name

由于需要编写跨平台工具,我无法使用 Windows API.

I am not able to use the Windows API due to the requirement to write a cross-platform tool.

推荐答案

您可以通过条件编译以跨平台方式解决此限制:

You could work around this limitation in a cross-platform way with conditional compilation:

#ifdef WIN32
     myFile = _wfopen( ... )
#else
     myFile = fopen( ... )
#endif

我认为任何重要的跨平台项目都必须在某处执行此操作,或者使用可以执行此操作的库(如 SDL).

I think any non-trivial cross-platform project will have to do this somewhere, or else use a library (like SDL) that does.

这篇关于使用 fopen 和 C 在 Windows 中打开长文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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