示范NTFS 卷上的硬链接
' Hardlinks.vbs
' 示范 NTFS 卷上的硬鏈接
' --------------------------------------------------------
Option Explicit
' 一些常量
Const L_NoHardLinkCreated = "Unable to create hard link"
Const L_EnterTarget = "Enter the file name to hard-link to"
Const L_HardLinks = "Creating hard link"
Const L_EnterHardLink = "Name of the hard link you want to create"
Const L_CannotCreate = "Make sure that both files are on the same volume and the volume is NTFS"
Const L_NotExist = "Sorry, the file doesn't exist"
Const L_SameName = "Target file and hard link cannot have the same name"
' 確定要(硬)鏈接的現有文件
dim sTargetFile
if WScript.Arguments.Count >0 then
?? sTargetFile = WScript.Arguments(0)
else
?? sTargetFile = InputBox(L_EnterTarget, L_HardLinks, "")
?? if sTargetFile = "" then WScript.Quit
end if
' 該文件存在嗎?
dim fso
set fso = CreateObject("Scripting.FileSystemObject")??
if Not fso.FileExists(sTargetFile) then
?? MsgBox L_NotExist
?? WScript.Quit
end if
' 主循環
while true
?? QueryForHardLink sTargetFile
wend
' 關閉
WScript.Quit
' /
' // Helper 函數
' 創建硬鏈接
'------------------------------------------------------------
function QueryForHardLink(sTargetFile)
?? ' 如果在命令行上指定了硬鏈接名,則提取它
?? dim sHardLinkName
?? if WScript.Arguments.Count >1 then
????? sHardLinkName = WScript.Arguments(1)
?? else
????? dim buf
????? buf = L_EnterHardLink & " for" & vbCrLf & sTargetFile
????? sHardLinkName = InputBox(buf, L_HardLinks, sTargetFile)
????? if sHardLinkName = "" then WScript.Quit??
????? if sHardLinkName = sTargetFile then
???????? MsgBox L_SameName
???????? exit function
????? end if
?? end if
?? ' 驗證兩個文件均在同一個卷上,且
?? ' 該卷是 NTFS
?? if Not CanCreateHardLinks(sTargetFile, sHardLinkName) then
????? MsgBox L_CannotCreate
????? exit function
?? end if
??
?? ' 創建硬鏈接
?? dim oHL
?? set oHL = CreateObject("HardLink.Object.1")
?? oHL.CreateNewHardLink sHardLinkName, sTargetFile
end function
' 驗證兩個文件均在同一個 NTFS 磁盤上
'------------------------------------------------------------
function CanCreateHardLinks(sTargetFile, sHardLinkName)
?? CanCreateHardLinks = false
??
?? dim fso
?? set fso = CreateObject("Scripting.FileSystemObject")
??
?? ' 同一個驅動器?
?? dim d1, d2
?? d1 = fso.GetDriveName(sTargetFile)
?? d2 = fso.GetDriveName(sHardLinkName)
?? if d1 <> d2 then exit function
?? ' NTFS 驅動器?
?? CanCreateHardLinks = IsNTFS(sTargetFile)
end function
' IsNTFS() — 驗證文件的卷是否為 NTFS
' --------------------------------------------------------
function IsNTFS(sFileName)
?? dim fso, drv
??
?? IsNTFS = False
?? set fso = CreateObject("Scripting.FileSystemObject")??
?? set drv = fso.GetDrive(fso.GetDriveName(sFileName))
?? set fso = Nothing
??
?? if drv.FileSystem = "NTFS" then IsNTFS = True
end function
轉載于:https://www.cnblogs.com/MaxWoods/archive/2006/05/09/395284.html
總結
以上是生活随笔為你收集整理的示范NTFS 卷上的硬链接的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: WPF 自定义窗口
- 下一篇: 在Delphi中关于UDP协议的实现