Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Reading Extended File Attributes on NTFS (Part 2)

Avatar of recurve
recurve asked on
20 Comments1 Solution3538 ViewsLast Modified:
I'm a complete scripting newb, so please forgive any stupidity.

I'm trying to do the same thing that the guy from the following thread wrote about (hence this thread title).

Reider wrote:
> Is it possible to read a files comments as added in windows
> explorer using the file system object in ASP.

> I'm using W2K server with SP3 and IIS 5

in this thread:
The consensus answer was, "No, it's not possible." But I found the following script somewhere at MSDN that seems read and write from named streams that could be extended file attributes (???). But I can't make it work so far because I can't seem to figure out the exact names of the attributes for things like "Comment" and "Title" and "Subject" (which you can turn in on Explorer in Windows 2000). Is this script a red herring? If not, what are the correct strings for the extended file attributes on NTFS? Thanks!

' CreateStream.vbs
' Demonstrates streams on NTFS volumes
' --------------------------------------------------------

Option Explicit

' Some constants
Const L_NotNTFS = "Sorry, the current volume is not NTFS."
Const L_EnterFile = "Enter a file name"
Const L_TestNTFS = "Test NTFS"
Const L_StdFile = "c:\testntfs\test.txt"
Const L_EnterStream = "Enter a stream name"
Const L_StdStream = "VersionInfo"
Const L_EnterTextStream = "Enter the text of the stream"
Const L_StdContent = "1.0"

' Makes sure the current volume is NTFS
if Not IsNTFS() then
   MsgBox L_NotNTFS
end if

' Query for a file name
dim sFileName
sFileName = InputBox(L_EnterFile, L_TestNTFS, L_StdFile)
if sFileName = "" then WScript.Quit

' Query for the stream to be written
dim sStreamName
sStreamName = InputBox (L_EnterStream, L_TestNTFS, L_StdStream)
if sStreamName = "" then WScript.Quit

' Initializes the FS object model
dim fso, bExist
set fso = CreateObject("Scripting.FileSystemObject")  

' Creates the file if it doesn't exist
dim ts
if Not fso.FileExists(sFileName) then
   set ts = fso.CreateTextFile(sFileName)
end if

' Try to read the current content of the stream
dim sFileStreamName, sStreamText
sFileStreamName = sFileName & ":" & sStreamName
if Not fso.FileExists(sFileStreamName) then
   sStreamText = L_StdContent
   set ts = fso.OpenTextFile(sFileStreamName)
   sStreamText = ts.ReadAll()
end if

' Query for the content of the stream to be written
sStreamText = InputBox (L_EnterTextStream, L_TestNTFS, sStreamText)
if sStreamText = "" then WScript.Quit

' Try to write to the stream
set ts = fso.CreateTextFile(sFileStreamName)
ts.Write sStreamText

' Close the app
set ts = Nothing
set fso = Nothing

' ////////////////////////////////////////////////////////
' // Helper functions

' IsNTFS() - Verifies whether the current volume is NTFS
' --------------------------------------------------------
function IsNTFS()
   dim fso, drv
   IsNTFS = False
   set fso = CreateObject("Scripting.FileSystemObject")  
   set drv = fso.GetDrive(fso.GetDriveName(WScript.ScriptFullName))
   set fso = Nothing
   if drv.FileSystem = "NTFS" then IsNTFS = True
end function
Avatar of markhoy
markhoyFlag of United Kingdom of Great Britain and Northern Ireland image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

This problem has been solved!
Unlock 1 Answer and 20 Comments.
See Answers