日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

示范NTFS 卷上的硬链接

發布時間:2023/12/20 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 示范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 卷上的硬链接的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。