系统文件夹

留下些什么 2004-09-07 11:00:55
如何获得系统文件夹的位置?
如果不用FSO,这怎样隐藏文件呢?
...全文
128 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
dongge2000 2004-09-07
  • 打赏
  • 举报
回复
20分偶也抢:
Option Explicit

Public Declare Function GetFileAttributes Lib "kernel32" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long
Public Declare Function SetFileAttributes Lib "kernel32" Alias "SetFileAttributesA" (ByVal lpFileName As String, ByVal dwFileAttributes As Long) As Long
Public Const FILE_ATTRIBUTE_READONLY = &H1
Public Const FILE_ATTRIBUTE_HIDDEN = &H2
Public Const FILE_ATTRIBUTE_SYSTEM = &H4

Enum wAtt
ReadOnly = 1
Hidden = 2
Readonly_Hidden = 3
System = 4
Hidden_System = 6
R_H_S = 7
All = 39
End Enum

Public Function File_AttRead(ByVal PathName As String, ByVal OutAtt As wAtt) As Boolean
On Error Resume Next
If GetFileAttributes(PathName) = -1 Then
File_AttRead = False

Else
OutAtt = GetFileAttributes(PathName)
End If
End Function

Public Function File_AttWirte(ByVal PathName As String, ByVal inAtt As wAtt) As Boolean
On Error Resume Next
If GetFileAttributes(PathName) = -1 Then
File_AttWirte = False
Else
SetFileAttributes PathName, inAtt
End If
End Function
'wAtt:
' 1=Readonly
' 2=Hidden
' 3=Readonly & Hidden
' 4=System
' 6=Hidden &System
' 7=Readonly & Hidden & System
' 32=Archive
' 39=All
-------------------------------------------------------------
Option Explicit

Public Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Public Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Public Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long

Public Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Public Function WinDir() As String
Dim S As String
Dim Z As Long
Dim R As Long
S = Space(254)
Z = Len(S)
R = GetWindowsDirectory(S, Z)
WinDir = Left(S, R)
WinDir = WinDir & "\"
End Function

Public Function SysDir() As String
Dim S As String
Dim Z As Long
Dim R As Long
S = Space(254)
Z = Len(S)
R = GetSystemDirectory(S, Z)
SysDir = Left(S, R)
SysDir = SysDir & "\"
End Function

Public Function TempDir() As String
Dim S As String
Dim Z As Long
Dim R As Long
S = Space(254)
Z = Len(S)
R = GetTempPath(Z, S)
TempDir = Left(S, R)
End Function

Public Function UserName() As String
Dim S As String
Dim Z As Long
Dim R As Long
S = Space(254)
Z = Len(S)
R = GetUserName(S, Z)
UserName = S
End Function

Public Function ComputerName() As String
Dim S As String
Dim Z As Long
Dim R As Long
S = Space(254)
Z = Len(S)
R = GetComputerName(S, Z)
ComputerName = S
End Function

tztz520 2004-09-07
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
Dim syspath As String
Dim len5 As Long

syspath = String(255, 0)
len5 = GetSystemDirectory(syspath, 256)
syspath = Left(syspath, InStr(1, syspath, Chr(0)) - 1)
Debug.Print "System Path : "; syspath
End Sub
online 2004-09-07
  • 打赏
  • 举报
回复
SetAttr 语句示例
本示例使用 SetAttr 语句来设置文件属性。

SetAttr"TESTFILE", vbHidden ' 设置隐含属性。
SetAttr"TESTFILE", vbHidden + vbReadOnly ' 设置隐含并只读。

online 2004-09-07
  • 打赏
  • 举报
回复
如果不用FSO,这怎样隐藏文件呢?


SetAttr 语句


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

语法

SetAttr pathname, attributes

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

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


设置值

attributes 参数设置可为:

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


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

说明

如果想要给一个已打开的文件设置属性,则会产生运行时错误。
laviewpbt 2004-09-07
  • 打赏
  • 举报
回复
改变文件属性
Private Declare Function GetFileAttributes Lib "kernel32" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long
Private Declare Function SetFileAttributes Lib "kernel32" Alias "SetFileAttributesA" (ByVal lpFileName As String, ByVal dwFileAttributes As Long) As Long
Private Const FILE_ATTRIBUTE_READONLY = &H1
Private Const FILE_ATTRIBUTE_HIDDEN = &H2
Private Const FILE_ATTRIBUTE_SYSTEM = &H4
Private Const FILE_ATTRIBUTE_DIRECTORY = &H10
Private Const FILE_ATTRIBUTE_ARCHIVE = &H20
Private Const FILE_ATTRIBUTE_NORMAL = &H80
Private Const FILE_ATTRIBUTE_TEMPORARY = &H100
Private Const FILE_ATTRIBUTE_COMPRESSED = &H800
Dim att As Long
Private Sub Command1_Click()
Dim mreadonly As Long
Dim mhide As Long
Dim marchive As Long
Dim msystem As Long
Dim s1 As String
Dim c1 As String
c1 = Chr(13) & Chr(10)
s1 = "D:\VB archives\vb6.0手册\VB6YY.WDL"
att = GetFileAttributes(s1)
If att <> 1 Then
mreadonly = att And FILE_ATTRIBUTE_READONLY
If mreadonly <> 0 Then S = "只读文件" & c1
mhidden = att And FILE_ATTRIBUTE_HIDDEN
If mhidden <> 0 Then S = "隐藏文件" & c1
marchive = att And FILE_ATTRIBUTE_ARCHIVE
If marchive <> 0 Then S = "存档文件" & c1
msystem = att And FILE_ATTRIBUTE_SYSTEM
If msystem <> 0 Then S = "系统文件"
End If
Text1.Text = s1 & "是:" & c1 & S

End Sub

Private Sub Command2_Click()
Dim sreadonly As Long
Dim shidden As Long
Dim sarchive As Long
Dim ssystem As Long
Dim rc As Long
Dim s1 As String
s1 = "D:\VB archives\vb6.0手册\VB6YY.WDL"
If Check1.Value Then
sreadonly = Not FILE_ATTRIBUTE_READONLY
End If
If Check2.Value Then
shidden = FILE_ATTRIBUTE_HIDDEN
End If
If Check3.Value Then
sarchive = Not FILE_ATTRIBUTE_ARCHIVE
End If
If Check4.Value Then
ssystem = Not FILE_ATTRIBUTE_SYSTEM
End If
Text1.Text = ""
If sreadonly Then att = att Or FILE_ATTRIBUTE_READONLY
If shidden Then att = att Or FILE_ATTRIBUTE_HIDDEN
If sarchive Then att = att Or FILE_ATTRIBUTE_ARCHIVE
If ssystem Then att = att Or FILE_ATTRIBUTE_SYSTEM
rc = SetFileAttributes(s1, att)

End Sub

Private Sub Form_Load()
Check1.Caption = "设置为只读文件"
Check2.Caption = "设置为隐藏文件"
Check3.Caption = "设置为存档文件"
Check4.Caption = "设置为系统文件"

End Sub
online 2004-09-07
  • 打赏
  • 举报
回复
' GetWindowsDirectory函数声明
Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" _
(ByVal lpBuffer As String, _
ByVal nSize As Long _
) As Long
' GetSystemDirectory函数声明
Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" _
(ByVal lpBuffer As String, _
ByVal nSize As Long _
) As Long
Dim S As String * 80
Dim Length As Long
Dim WinPath As String
Dim SysPath As String
Private Sub Command1_Click()
MsgBox ("Windows安装目录是:" + WinPath)
End Sub

Private Sub Command2_Click()
MsgBox ("系统所在目录是:" + SysPath)
End Sub

' 获取Windows目录和系统目录的程序代码
Private Sub Form_Load()

Length = GetWindowsDirectory(S, Len(S))
WinPath = Left(S, Length)
Length = GetSystemDirectory(S, Len(S))
SysPath = Left(S, Length)
End Sub
zcm123 2004-09-07
  • 打赏
  • 举报
回复

Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Public Declare Function GetProfileString Lib "kernel32" Alias "GetProfileStringA" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long) As Long
Public Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Public Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Public Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Public Declare Function WriteProfileString Lib "kernel32" Alias "WriteProfileStringA" (ByVal lpszSection As String, ByVal lpszKeyName As String, ByVal lpszString As String) As Long
Public Declare Function GetFullPathName Lib "kernel32" Alias "GetFullPathNameA" (ByVal lpFileName As String, ByVal nBufferLength As Long, ByVal lpBuffer As String, ByVal lpFilePart As String) As Long
Public Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long

Function ReadIni(AppName As String, KeyName As String, FileName As String) '/读取非系统ini
Dim Ret As String
Dim NC As Integer
Ret = String(1024, 0)
NC = GetPrivateProfileString(AppName, KeyName, "", Ret, 1024, FileName)
If NC <> 0 Then Ret = Left$(Ret, Len(Ret) - 1024 + NC) Else Ret = ""
ReadIni = Ret
End Function

Function WriteIni(AppName As String, KeyName As String, lpString As String, FileName As String) '/写入非系统ini
WritePrivateProfileString AppName, KeyName, lpString, FileName
End Function

Function ReadSystemIni(AppName As String, KeyName As String) '/读取系统ini
Dim Ret As String
Dim NC As Integer
Ret = String(1024, 0)
NC = GetProfileString(AppName, KeyName, "", Ret, 1024)
If NC <> 0 Then Ret = Left$(Ret, Len(Ret) - 1024 + NC) Else Ret = ""
ReadSystemIni = Ret
End Function

Function WriteSystemIni(AppName As String, KeyName As String, lpString As String) '/写系统ini
WriteProfileString AppName, KeyName, lpString
End Function

Function SystemPath() As String '/获得系统路径
Dim SystemDirectory As String
Dim x As Long
SystemDirectory = String(1024, 0)
x = GetSystemDirectory(SystemDirectory, 1024)
SystemPath = Left$(SystemDirectory, Len(SystemDirectory) - 1024 + x)
End Function

Function WindowsPath() As String '/获得windows路径
Dim WindowsDirectory As String
Dim x As Long
WindowsDirectory = String(1024, 0)
x = GetWindowsDirectory(WindowsDirectory, 1024)
WindowsPath = Left$(WindowsDirectory, Len(WindowsDirectory) - 1024 + x)
End Function

Function TempPath() As String '/获得临时文件路径
Dim TempDirectory As String
Dim x As Long
TempDirectory = String(1024, 0)
x = GetTempPath(1024, TempDirectory)
TempPath = Left$(TempDirectory, Len(TempDirectory) - 1024 + x)
End Function



内容概要:本文提出并实证验证了“认知虫洞”的存在,将其定义为思维状态空间中连接遥远概念域的拓扑隧道,是创造性突破的拓扑本质。通过构建对话流形、定义认知虫洞的数学条件(如类光测地线束、负曲率喉颈、穿越时间<300ms等),开发CHC算法实现多项式时间内检测,并结合fMRI与EEG数据证实其神经相关性——默认模式网络与突显网络相位同步增强、前额叶theta-gamma耦合与喉颈半径正相关。实验表明认知虫洞密度与远距离联想能力显著正相关,且可作为创造性预测标志。进一步工程化实现“虫洞协议”系统,通过多模态输入实时检测并增强认知虫洞,显著提升跨领域问题解决效率(平均解决率提升56%),并在团队协作、临床治疗、教育等领域展现广泛应用潜力。; 适合人群:具备认知科学、复杂网络或拓扑学基础,从事创造性研究、人工智能、神经科学或教育创新的研发人员与学者;对跨学科思维机制感兴趣的高阶学习者。; 使用场景及目标:①理解创造性突破的拓扑机制,识别思维中“顿悟”的结构性特征;②利用CHC算法与“虫洞协议”系统在科研协作、创新设计、心理干预等场景中主动诱导和增强跨域联想能力;③开展认知拓扑学相关的理论研究与技术开发。; 阅读建议:此资源融合微分拓扑、神经科学与算法工程,建议结合附录代码与公开数据集进行实践复现,重点关注定理推导、算法实现与实证结果之间的闭环验证关系,深入理解从理论建模到应用落地的完整路径。

7,789

社区成员

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

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