dongge2000(秋日私语) :怎么揭开隐藏的设置?100分

djs001 2004-08-01 11:16:33
你知道的。
...全文
140 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
rainstormmaster 2004-08-01
  • 打赏
  • 举报
回复
//谢谢gdami(糖米) ,不过用SetFileAttributes设置文件夹隐藏属性后,即使选择了“查看所有文件和文件夹”也看不到被隐藏的文件夹。如果使用Attributes ,能达到这个效果吗?我没有去试

不能,因为Attributes是用SetFileAttributes封装的,你的问题我看了,简单的说,如果只用vb的话,解决不了
djs001 2004-08-01
  • 打赏
  • 举报
回复
刚弄完,用setattr没有我说的效果。
djs001 2004-08-01
  • 打赏
  • 举报
回复
谢谢gdami(糖米) ,不过用SetFileAttributes设置文件夹隐藏属性后,即使选择了“查看所有文件和文件夹”也看不到被隐藏的文件夹。如果使用Attributes ,能达到这个效果吗?我没有去试。
gdami 2004-08-01
  • 打赏
  • 举报
回复
这都是vb自带的函数,不是api。 可以用下面的属性来查看文件的是否隐藏。

Attributes属性
描述

设置或者返回文件或文件夹的属性。读/写或只读,取决于属性。

语法

object.Attributes [= newattributes]

Attributes 属性有下列几个部分:

部分 描述
object 必需的。总是某个 File 或者 Folder 对象的名字。
newattributes 可选的。如果提供的话,newattributes 就是所指定 object 的新属性值。


设置

newattributes 参数可以是具有下列值中的任意一个或任意的逻辑组合:

常数 值 描述
Normal 0 一般文件。未设置属性。
ReadOnly 1 只读文件。属性为读/写。
Hidden 2 隐藏文件。属性为读/写。
System 4 系统文件。属性为读/写。
Volume 8 磁盘驱动器卷标。属性为只读。
Directory 16 文件夹或目录。属性为只读。
Archive 32 自上次备份后已经改变的文件。属性为读/写。
Alias 64 链接或快捷方式。属性为只读。
Compressed 128 压缩文件。属性为只读。


说明

下面的代码用一个文件举例说明了 Attributes 属性的用法:

Sub SetClearArchiveBit(filespec)
Dim fs, f, r
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(fs.GetFileName(filespec))
If f.attributes and 32 Then
r = MsgBox("The Archive bit is set, do you want to clear it?", vbYesNo, "Set/Clear Archive Bit")
If r = vbYes Then
f.attributes = f.attributes - 32
MsgBox "Archive bit is cleared."
Else
MsgBox "Archive bit remains set."
End If
Else
r = MsgBox("The Archive bit is not set. Do you want to set it?", vbYesNo, "Set/Clear Archive Bit")
If r = vbYes Then
f.attributes = f.attributes + 32
MsgBox "Archive bit is set."
Else
MsgBox "Archive bit remains clear."
End If
End If
End Sub
daisy8675 2004-08-01
  • 打赏
  • 举报
回复
既然是送分贴,那就不属于恶意分哦,那我就删除咯 :P
哈哈~~呵呵

今天就找找你麻烦啦啊,呵呵
gdami 2004-08-01
  • 打赏
  • 举报
回复
SetAttr语句

为一个文件设置属性信息。

语法

SetAttr pathname, attributes

SetAttr 语句的语法含有以下这些命名参数:

部分 描述
pathname 必要参数。用来指定一个文件名的字符串表达式,可能包含目录或文件夹、以及驱动器。
Attributes 必要参数。常数或数值表达式,其总和用来表示文件的属性。


设置值

attributes 参数设置可为:

常数 值 描述
vbNormal 0 常规(缺省值)
VbReadOnly 1 只读。
vbHidden 2 隐藏。
vbSystem 4 系统文件
vbArchive 32 上次备份以后,文件已经改变


注意 这些常数是由 VBA 所指定的,在程序代码中的任何位置,可以使用这些常数来替换真正的数值。

说明

如果想要给一个已打开的文件设置属性,则会产生运行时错误。
djs001 2004-08-01
  • 打赏
  • 举报
回复
有兴趣的朋友请看:http://community.csdn.net/Expert/topic/3230/3230708.xml?temp=.6737329
djs001 2004-08-01
  • 打赏
  • 举报
回复
32=Archive
djs001 2004-08-01
  • 打赏
  • 举报
回复
哈哈,各位大侠,此贴专为送分而设,不好意思,其实仅仅是为了SetFileAttributes函数,设置文件夹的属性问题。对不起。
daisy8675 2004-08-01
  • 打赏
  • 举报
回复
??问的问题都不清不楚
djs001 2004-08-01
  • 打赏
  • 举报
回复
我最终使用了GetFileAttributes 和setFileAttributes 函数。我还有其他一个问题,有兴趣的请看:(不好意思,我比较新手,其中可能有写误会)
http://community.csdn.net/Expert/topic/3231/3231262.xml?temp=.7050135


谢谢大家给的资料!!!
djs001 2004-08-01
  • 打赏
  • 举报
回复
唉,不好意思,dongge2000(秋日私语) ,同志们太热情了,你不介意我分一些给大家吧?
dongge2000 2004-08-01
  • 打赏
  • 举报
回复
上个贴子我以回复了,第二个问题我也不大会,你再问问吧,十分不好意思!
:(
rainstormmaster 2004-08-01
  • 打赏
  • 举报
回复
GetFileAttributes:

【VB声明】
Private Declare Function GetFileAttributes Lib "kernel32" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long

【别名】
GetFileAttributesA

【说明】
判断指定文件的属性

【返回值】
Long,-1表示出错。如返回包含了标志的一个Long值,则指定文件的属性。其中的标志对应于带有FILE_ATTRIBUTE_???前缀的常数。具体参考BY_HANDLE_FILE_INFORMATION结构的File Attribute Types
table表格

【参数表】
lpFileName ----- String,指定欲获取属性的一个文件的名字

rainstormmaster 2004-08-01
  • 打赏
  • 举报
回复
//SetFileAttributes函数的具体介绍rainstormmaster(暴风雨 v2.0) 你有吗?能贴出来吗?好象还有一个GetFileAttributes 函数。谢谢。

SetFileAttributes:
【VB声明】
Private Declare Function SetFileAttributes Lib "kernel32" Alias "SetFileAttributesA" (ByVal lpFileName As String, ByVal dwFileAttributes As Long) As Long

【别名】
SetFileAttributesA
【说明】
设置文件属性
【返回值】
Long,非零表示成功,零表示失败。会设置GetLastError
【参数表】
lpFileName ----- String,要设置其属性的文件名
dwFileAttributes - Long,带有FILE_ATTRIBUTE_??前缀的一个或多个常数
例子:
Const MOVEFILE_REPLACE_EXISTING = &H1
Const FILE_ATTRIBUTE_TEMPORARY = &H100
Const FILE_BEGIN = 0
Const FILE_SHARE_READ = &H1
Const FILE_SHARE_WRITE = &H2
Const CREATE_NEW = 1
Const OPEN_EXISTING = 3
Const GENERIC_READ = &H80000000
Const GENERIC_WRITE = &H40000000
Private Declare Function SetVolumeLabel Lib "kernel32" Alias "SetVolumeLabelA" (ByVal lpRootPathName As String, ByVal lpVolumeName As String) As Long
Private Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Any) As Long
Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, ByVal lpOverlapped As Any) As Long
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function SetFilePointer Lib "kernel32" (ByVal hFile As Long, ByVal lDistanceToMove As Long, lpDistanceToMoveHigh As Long, ByVal dwMoveMethod As Long) As Long
Private Declare Function SetFileAttributes Lib "kernel32" Alias "SetFileAttributesA" (ByVal lpFileName As String, ByVal dwFileAttributes As Long) As Long
Private Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long
Private Declare Function GetTempFileName Lib "kernel32" Alias "GetTempFileNameA" (ByVal lpszPath As String, ByVal lpPrefixString As String, ByVal wUnique As Long, ByVal lpTempFileName As String) As Long
Private Declare Function MoveFileEx Lib "kernel32" Alias "MoveFileExA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal dwFlags As Long) As Long
Private Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long
Private Sub Form_Load()
'KPD-Team 1998
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Dim sSave As String, hOrgFile As Long, hNewFile As Long, bBytes() As Byte
Dim sTemp As String, nSize As Long, Ret As Long
'Ask for a new volume label
sSave = InputBox("Please enter a new volume label for drive C:\" + vbCrLf + " (if you don't want to change it, leave the textbox blank)")
If sSave <> "" Then
SetVolumeLabel "C:\", sSave
End If

'Create a buffer
sTemp = String(260, 0)
'Get a temporary filename
GetTempFileName "C:\", "KPD", 0, sTemp
'Remove all the unnecessary chr$(0)'s
sTemp = Left$(sTemp, InStr(1, sTemp, Chr$(0)) - 1)
'Set the file attributes
SetFileAttributes sTemp, FILE_ATTRIBUTE_TEMPORARY
'Open the files
hNewFile = CreateFile(sTemp, GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0, 0)
hOrgFile = CreateFile("c:\config.sys", GENERIC_READ, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0, 0)

'Get the file size
nSize = GetFileSize(hOrgFile, 0)
'Set the file pointer
SetFilePointer hOrgFile, Int(nSize / 2), 0, FILE_BEGIN
'Create an array of bytes
ReDim bBytes(1 To nSize - Int(nSize / 2)) As Byte
'Read from the file
ReadFile hOrgFile, bBytes(1), Ubound(bBytes), Ret, ByVal 0&
'Check for errors
If Ret <> Ubound(bBytes) Then MsgBox "Error reading file ..."

'Write to the file
WriteFile hNewFile, bBytes(1), Ubound(bBytes), Ret, ByVal 0&
'Check for errors
If Ret <> Ubound(bBytes) Then MsgBox "Error writing file ..."

'Close the files
CloseHandle hOrgFile
CloseHandle hNewFile

'Move the file
MoveFileEx sTemp, "C:\KPDTEST.TST", MOVEFILE_REPLACE_EXISTING
'Delete the file
DeleteFile "C:\KPDTEST.TST"
Unload Me
End Sub


djs001 2004-08-01
  • 打赏
  • 举报
回复
晕!哈哈
gdami 2004-08-01
  • 打赏
  • 举报
回复
GetFileAttributes
The GetFileAttributes function returns attributes for a specified file or directory.

DWORD GetFileAttributes(
LPCTSTR lpFileName // pointer to the name of a file or directory
);

Parameters
lpFileName
Pointer to a null-terminated string that specifies the name of a file or directory.
Windows NT:
There is a default string size limit for paths of MAX_PATH characters. This limit is related to how the GetFileAttributes function parses paths. An application can transcend this limit and send in paths longer than MAX_PATH characters by calling the wide (W) version of GetFileAttributes and prepending "\\?\" to the path. The "\\?\" tells the function to turn off path parsing; it lets paths longer than MAX_PATH be used with GetFileAttributesW. However, each component in the path cannot be more than MAX_PATH characters long. This also works with UNC names. The "\\?\" is ignored as part of the path. For example, "\\?\C:\myworld\private" is seen as "C:\myworld\private", and "\\?\UNC\bill_g_1\hotstuff\coolapps" is seen as "\\bill_g_1\hotstuff\coolapps".
Windows 95:
The lpFileName string must not exceed MAX_PATH characters. Windows 95 does not support the "\\?\" prefix.
Return Values
If the function succeeds, the return value contains the attributes of the specified file or directory.

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

The attributes can be one or more of the following values:

Attribute Meaning
FILE_ATTRIBUTE_ARCHIVE The file or directory is an archive file or directory. Applications use this attribute to mark files for backup or removal.
FILE_ATTRIBUTE_COMPRESSED The file or directory is compressed. For a file, this means that all of the data in the file is compressed. For a directory, this means that compression is the default for newly created files and subdirectories.
FILE_ATTRIBUTE_DIRECTORY The handle identifies a directory.
FILE_ATTRIBUTE_ENCRYPTED The file or directory is encrypted. For a file, this means that all data streams are encrypted. For a directory, this means that encryption is the default for newly created files and subdirectories.
FILE_ATTRIBUTE_HIDDEN The file or directory is hidden. It is not included in an ordinary directory listing.
FILE_ATTRIBUTE_NORMAL The file or directory has no other attributes set. This attribute is valid only if used alone.
FILE_ATTRIBUTE_OFFLINE The data of the file is not immediately available. Indicates that the file data has been physically moved to offline storage.
FILE_ATTRIBUTE_READONLY The file or directory is read-only. Applications can read the file but cannot write to it or delete it. In the case of a directory, applications cannot delete it.
FILE_ATTRIBUTE_REPARSE_POINT The file has an associated reparse point.
FILE_ATTRIBUTE_SPARSE_FILE The file is a sparse file.
FILE_ATTRIBUTE_SYSTEM The file or directory is part of, or is used exclusively by, the operating system.
FILE_ATTRIBUTE_TEMPORARY The file is being used for temporary storage. File systems attempt to keep all of the data in memory for quicker access rather than flushing the data back to mass storage. A temporary file should be deleted by the application as soon as it is no longer needed.


Remarks
Windows CE: Windows CE supports the following additional return values:

FILE_ATTRIBUTE_INROM
This file is an operating system file stored in ROM. These files are read-only; they cannot be modified.
FILE_ATTRIBUTE_ROMMODULE
This file is an operating system file stored in ROM, designed to execute in place. In other words, code from this file is executed directly from ROM, rather than being first copied to RAM. The CreateFile function cannot be used to access this file, instead the LoadLibrary and CreateProcess functions must be used.
QuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Requires version 1.0 or later.
Header: Declared in winbase.h.
Import Library: Use kernel32.lib.
Unicode: Implemented as Unicode and ANSI versions on Windows NT.

See Also
File I/O Overview, File Functions, DeviceIoControl, FindFirstFile, FindNextFile, SetFileAttributes


gdami 2004-08-01
  • 打赏
  • 举报
回复
SetFileAttributes
The SetFileAttributes function sets a file's attributes.

BOOL SetFileAttributes(
LPCTSTR lpFileName, // pointer to filename
DWORD dwFileAttributes // attributes to set
);

Parameters
lpFileName
Pointer to a string that specifies the name of the file whose attributes are to be set.
Windows 95: This string must not exceed MAX_PATH characters.

Windows NT: There is a default string size limit for paths of MAX_PATH characters. This limit is related to how the SetFileAttributes function parses paths. An application can transcend this limit and send in paths longer than MAX_PATH characters by calling the wide (W) version of SetFileAttributes and prepending "\\?\" to the path. However, each component in the path cannot be more than MAX_PATH characters long. The "\\?\" tells the function to turn off path parsing; it lets paths longer than MAX_PATH be used with SetFileAttributesW. However, each component in the path cannot be more than MAX_PATH characters long. This also works with UNC names. The "\\?\" is ignored as part of the path. For example, "\\?\C:\myworld\private" is seen as "C:\myworld\private", and "\\?\UNC\wow\hotstuff\coolapps" is seen as "\\wow\hotstuff\coolapps".

dwFileAttributes
Specifies the file attributes to set for the file. This parameter can be a combination 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_OFFLINE The data of the file is not immediately available. Indicates that the file data has been physically moved to offline storage.
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 attempt to keep all of the data in memory for quicker access rather than flushing the data back to mass storage. A temporary file should be deleted by the application as soon as it is no longer needed.


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_DIRECTORY Files cannot be converted into directories. To create a directory, use the CreateDirectory or CreateDirectoryEx function.
FILE_ATTRIBUTE_ENCRYPTED To encrypt a file, use the EncryptFile function.
FILE_ATTRIBUTE_REPARSE_POINT To associate a reparse point with a file, 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.
FILE_ATTRIBUTE_SYSTEM This attribute cannot be set.


Windows CE: If the function succeeds, the return value is TRUE. If the function fails, the return value is FALSE. To get extended error information, call GetLastError.

QuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Requires version 1.0 or later.
Header: Declared in winbase.h.
Import Library: Use kernel32.lib.
Unicode: Implemented as Unicode and ANSI versions on Windows NT.

See Also
File I/O Overview, File Functions, GetFileAttributes


djs001 2004-08-01
  • 打赏
  • 举报
回复
//不能,因为Attributes是用SetFileAttributes封装的,你的问题我看了,简单的说,如果只用vb的话,解决不了

用api函数隐藏了一个文件夹后,除了用dir /ah查看到以外,还能用什么方法查看?SetFileAttributes函数的具体介绍rainstormmaster(暴风雨 v2.0) 你有吗?能贴出来吗?好象还有一个GetFileAttributes 函数。谢谢。
flyingZFX 2004-08-01
  • 打赏
  • 举报
回复
???????????????///

1,488

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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