os.link & NTFS 5
yaipa
yaipa at aol.com
Sat Dec 28 00:22:34 EST 2002
Sorry, not use to 'browsing' on a 15" monitor. ;^)
... and the rest of the story...
/*** Begin SRC Post ***/
'
' Hardlinks.vbs
' Demonstrates hard links on NTFS volumes
' --------------------------------------------------------
Option Explicit
' Some constants
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"
' Determine the existing file to (hard) link to
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
' Does the file exist?
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 up
WScript.Quit
'
' /////////////////////////////////////////////////////////////
' // Helper Functions
' Create the hard link
'------------------------------------------------------------
function QueryForHardLink(sTargetFile)
' Extract the hard link name if specified on the command line
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
' 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
' Creates the 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 <> d2 then exit function
' NTFS drive?
CanCreateHardLinks = IsNTFS(sTargetFile)
end function
'
' IsNTFS() - Verifies whether the file's 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
/*** End SRC Post ***/
~~~~~~~~~~~~~~~~~~~~
"DP" <pennedinil at excite.com> wrote in message news:<auf11l$ibo16 at news.emirates.net.ae>...
> [Not sure if my previous post made it, so reposting]
>
> I'm looking for the equivalent of os.link and os.symlink for Python/WinXP
> (i.e., NTFS 5). These functions seem to be available only on Python/UNIX.
> They're also available on Python/Cygwin.I haven't found anything similar to
> this for Win32 platforms.
>
> I'm copying source files to directories named as
> TARGET\data_val_a\data_val_b\* as well as TARGET\data_val_b\data_val_a\*.
> data_val_{a|b} are values parsed from the files being copied. I'd prefer to
> save the two copies of files as links to preserve disk space and ease file
> management.
>
> I also need a means of manipulating file permissions and properties from
> within Python. What's the best way of going about this? Again, I just don't
> know enough.
>
> Another application is font management. With Windows, Cygwin, XFree,
> ghostscript (Cygwin & Win32), Adobe products, GNUWin32 tools, MikTex, Latex
> for Cygwin, etc. all creating their own font directories, managing the font
> files is turning out to be extremely difficult. I'd rather have these saved
> as a single copy linked into the other directories.
>
> Obviously there are other applications.
>
> Thanks in advance.
>
> Dinil.
>
> If possible, please forward a copy of responses to pennedinil @ excite.com.
> I don't have access to a news server, so I'm only able to view responses
> from 6 to 10 hours after they're posted.
More information about the Python-list
mailing list