Demonstrate hard links on NTFS volumes

Source: Internet
Author: User

'Hardlinks. vbs
'Demonstrate the hard link on the NTFS Volume
'--------------------------------------------------------

Option explicit

'Some Constants
Const l_nohardlinkcreated = "unable to create hard link"
Const l_entertarget = "Enter the file name to hard-link"
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"

'Are you sure you want to (hard) link the existing file
Dim stargetfile
If wscript. Arguments. Count & gt; 0 then
Stargetfile = wscript. Arguments (0)
Else
Stargetfile = inputbox (l_entertarget, l_hardlinks ,"")
If stargetfile = "" Then wscript. Quit
End if

'The file exists?
Dim FSO
Set FSO = Createobject ("scripting. FileSystemObject ")
If not FSO. fileexists (stargetfile) then
Msgbox l_notexist
Wscript. Quit
End if

'Main Loop
While true
Queryforhardlink stargetfile
Wend

'Close
Wscript. Quit

'/////////////////////////////////////// //////////////////////
'// Helper Function

'create a hard link
'------------------------------------------------------
function queryforhardlink (stargetfile)
' If a hard link name is specified on the command line, extract it
dim shardlinkname
If wscript. arguments. count & gt; 1 then
shardlinkname = wscript. arguments (1)
else
dim Buf
Buf = l_enterhardlink & amp; "for" & amp; vbcrlf & amp; stargetfile
shardlinkname = inputbox (BUF, l_hardlinks, stargetfile)
If shardlinkname = "" Then wscript. quit
If shardlinkname = stargetfile then
msgbox l_samename
exit function
end if

'verify that both files are on the same volume and
'the volume is NTFS
if not cancreatehardlinks (stargetfile, shardlinkname) then
msgbox l_cannotcreate
exit function
end if
'create a hard link
dim Ohl
set Ohl = Createobject (" hardlink. object.1 ")
Ohl. createnewhardlink shardlinkname, stargetfile
end function

'Verify that both files are on the same NTFS disk.
'------------------------------------------------------------
Function cancreatehardlinks (stargetfile, shardlinkname)
Cancreatehardlinks = false

Dim FSO
Set FSO = Createobject ("scripting. FileSystemObject ")

'Same drive?
Dim D1, D2
D1 = FSO. getdrivename (stargetfile)
D2 = FSO. getdrivename (shardlinkname)
If D1 & lt; & gt; d2 then exit function

'Ntfs drive?
Cancreatehardlinks = isntfs (stargetfile)
End Function

'isntfs ()-verify whether the file volume is 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.