关于创建文件夹? VC6.0+Win2000

坦壇 2005-04-06 05:52:51

BOOL bCreateFolder = CreateDirectory(path_create,NULL);
这种方式编译后,程序在2000系统下面正常,
可是在XP系统中创建的文件夹自动变为只读属性,
怎么将该文件夹强行改为可写?
另外用 _wmkdir(path_create);我也试过~ 也不行。
...全文
243 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
坦壇 2005-04-10
  • 打赏
  • 举报
回复
呵呵,我的错, 这两天工作紧张。
vcmute(横秋) 说的很有道理,最后发现问题出在另外一个团队提供的COM库的问题,不过从这里明白了很多东西,谢谢各位。
surstar 2005-04-07
  • 打赏
  • 举报
回复
GetFileAttributes获得文件属性
SetFileAttributes修改属性

这都不行吗? 应该可以了吧,楼主也不来回应
dirdirdir3 2005-04-07
  • 打赏
  • 举报
回复
可以直接写的,不用另外设置。
goodheartppl 2005-04-07
  • 打赏
  • 举报
回复
帮你测过了 用 ::SetFileAttributes(tempFileName,dWold);


SetFileAttributes

The SetFileAttributes function sets a file's attributes.


BOOL SetFileAttributes(
LPCTSTR lpFileName,
DWORD dwFileAttributes
);

Parameters
lpFileName
[in] Pointer to a string that specifies the name of the file whose attributes are to be set.
In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see Naming a File.

Windows Me/98/95: This string must not exceed MAX_PATH characters.
dwFileAttributes
[in] File attributes to set for the file. This parameter can be one or more of the following values. However, all other values override FILE_ATTRIBUTE_NORMAL. Attribute Meaning
FILE_ATTRIBUTE_ARCHIVE The file is an archive file. Applications use this attribute to mark files for backup or removal.
FILE_ATTRIBUTE_HIDDEN The file is hidden. It is not included in an ordinary directory listing.
FILE_ATTRIBUTE_NORMAL The file has no other attributes set. This attribute is valid only if used alone.
FILE_ATTRIBUTE_NOT_CONTENT_INDEXED The file will not be indexed by the content indexing service.
FILE_ATTRIBUTE_OFFLINE The data of the file is not immediately available. This attribute indicates that the file data has been physically moved to offline storage. This attribute is used by Remote Storage, the hierarchical storage management software. Applications should not arbitrarily change this attribute.
FILE_ATTRIBUTE_READONLY The file is read-only. Applications can read the file but cannot write to it or delete it.
FILE_ATTRIBUTE_SYSTEM The file is part of the operating system or is used exclusively by it.
FILE_ATTRIBUTE_TEMPORARY The file is being used for temporary storage. File systems avoid writing data back to mass storage if sufficient cache memory is available, because often the application deletes the temporary file shortly after the handle is closed. In that case, the system can entirely avoid writing the data. Otherwise, the data will be written after the handle is closed.

Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks
The following table describes how to set the attributes that cannot be set using SetFileAttributes.

Attribute How to Set
FILE_ATTRIBUTE_COMPRESSED To set a file's compression state, use the DeviceIoControl function with the FSCTL_SET_COMPRESSION operation.
FILE_ATTRIBUTE_DEVICE Reserved; do not use.
FILE_ATTRIBUTE_DIRECTORY Files cannot be converted into directories. To create a directory, use the CreateDirectory or CreateDirectoryEx function.
FILE_ATTRIBUTE_ENCRYPTED To create an encrypted file, use the CreateFile function with the FILE_ATTRIBUTE_ENCRYPTED attribute. To convert an existing file into an encrypted file, use the EncryptFile function.
FILE_ATTRIBUTE_REPARSE_POINT To associate a reparse point with a file or directory, use the DeviceIoControl function with the FSCTL_SET_REPARSE_POINT operation.
FILE_ATTRIBUTE_SPARSE_FILE To set a file's sparse attribute, use the DeviceIoControl function with the FSCTL_SET_SPARSE operation.



Windows Me/98/95: SetFileAttributesW is supported by the Microsoft Layer for Unicode. To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.

Example Code
For an example, see Retrieving and Changing File Attributes.

Requirements
Client: Requires Windows XP, Windows 2000 Professional, Windows NT Workstation, Windows Me, Windows 98, or Windows 95.
Server: Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server.
Unicode: Implemented as Unicode and ANSI versions. Note that Unicode support on Windows Me/98/95 requires Microsoft Layer for Unicode.
Header: Declared in Winbase.h; include Windows.h.
Library: Use Kernel32.lib.



Practise_Think 2005-04-06
  • 打赏
  • 举报
回复
在你的代码后面再用SetFileAttributes()强制改变其属性就可以了,无论在2K还是XP也不要紧
xuzheng318 2005-04-06
  • 打赏
  • 举报
回复
This function returns attributes for a specified file or directory. A remote application programming interface (RAPI) version of this function exists, and it is named CeGetFileAttributes (RAPI).

DWORD GetFileAttributes(
LPCTSTR lpFileName
);




This function sets the attributes of a file. A remote application programming interface (RAPI) version of this function exists, and it is called CeSetFileAttributes (RAPI).

BOOL SetFileAttributes(
LPCTSTR lpFileName,
DWORD dwFileAttributes
);
oyljerry 2005-04-06
  • 打赏
  • 举报
回复
GetFileAttributes获得文件属性
SetFileAttributes修改属性
vcmute 2005-04-06
  • 打赏
  • 举报
回复
XP下只是半只读状态
但并不影响正常使用
系统也不能改其状态
Kudeet 2005-04-06
  • 打赏
  • 举报
回复
DWORD dWold;
dWold=::GetFileAttributes(tempFileName);
dWold&=~FILE_ATTRIBUTE_READONLY;
::SetFileAttributes(tempFileName,dWold);
signoft 2005-04-06
  • 打赏
  • 举报
回复
楼主在创建完文件夹之后加上一下一句
//文件和文件夹都适用
::SetFileAttributes(strMyDir/*创建文件夹绝对路径*/,FILE_ATTRIBUTE_NORMAL);

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧