i need to add explanation to my file
i have a little filesystem in my program (so i dont want to use database for files)
how can i add and call explanation to myfile
i have some ideas but thats last resort couse its not not efficient and hard to make :)
i thought i should create new table for my filesystem notes... (but its not useful)

so is there any easy way to do this :) i mean when we use explorer we can right click and use some field for our explanations.Is it possible to be able to use this fields.

thx for replys :)

Recommended Answers

All 5 Replies

i have a little filesystem in my program

If you use your own filesystem and you don't need any Explorer integration, I would suggest using a new table or some hidden extra file with filenames and their explanations.

The second approach may be much harder to program: use alternate data streams (ADS). If you're not familiar with ADS read this tutorial first: Windows Alternate Data Streams
If you decide to give it a try here's two more articles: ADSdotNET: A DLL for using alternate data streams from .net languages and Manipulate Alternate Data Streams.
The first one would be a ready-to-go DLL but the second article would show you how to do it yourself. There's just one point: no VB but pure C++ and C#, so you should be a bit familiar with those languages.

HTH

First of all - the following only works on NTFS file systems and uses (as suggested by Teme64) alternate data streams which are pretty cool and very easy to work with.

Funny you should bring this up. I wanted the ability to add a comment to a file (any type of file) so i wrote two programs. One is in vb.net and provides a simple multi-line edit box. When it loads it initializes the edit text to whatever text was in the clipboard. When it exits it writes the edit text back into the clipboard.

The second program (comment.py) was written in Python and I use it as follows:

comment

Shows a brief help summary

comment <pattern>

Lists the comment for every file (that has a comment) that matches the
given file pattern (eg *.avi)

comment <pattern> e|edit

Edits the comment for every file that matches the given file pattern. The
editing is done in a GUI edit box. If there is an existing comment then
the box is loaded with that comment. The comment is saved back to the
file when the edit box is closed.

I would be happy to provide you with the code for both. You should be able to use the techniques in both to do what you want. The second program could easily be folded into the first.

I had a look at alternate data streams in VB and it turns out that it is far easier to do in vbScript than in vb so here it is:

set fso = CreateObject("Scripting.FileSystemObject")
set arg = Wscript.Arguments

const STREAM = ":comment"

howto = "" _
      & "\n\ncomment" _
      & "\n\n    show brief help (this)" _
      & "\n\ncomment filename" _
      & "\n\n    show comment for this file" _
      & "\n\ncomment filename ""This is a comment""" _
      & "\n\n    set comment for this file"

Select case arg.Count
    Case 1
        Wscript.Echo "comment: " & getComment(arg(0))
    Case 2
        Wscript.Echo "set comment to: " & setComment(arg(0), arg(1))
    Case Else
        Wscript.Echo Replace(howto,"\n", vbCrLf)
End Select

Function getComment(ByVal filename)

    streamname = filename & STREAM

    if fso.FileExists(streamname) then
        getComment = fso.OpenTextFile(streamname).ReadAll
    else
        getComment = "no comment"
    end if
    
End Function

Function setComment(ByVal filename, ByVal comment)

    streamname = filename & STREAM
    fso.OpenTextFile(streamname,2,True).Write(comment)
    setComment = comment

End Function

If you want to delete a comment then just fso.DeleteFile(streamname). And if you want to be able to add multi line comments of any size I'll be happy to give you all the python and vb code.

I had a look at alternate data streams in VB and it turns out that it is far easier to do in vbScript

OP needs VB.NET solution. You're right about that the vbscript is much easier to use in here. NET solution needs few P/Invokes but once you've wrapped all in a one neat DLL, you can forget all that low-level stuff. First link pointed to a DLL that's written in C++. Of course, this DLL can be written with plain VB.NET too.

If you really need it in vb.Net then just use the above code slightly modified. I realized after I posted that you can create the Scripting.FileSystemObject as easily from vb.Net as from vbScript. The vb.Net code is then

Module Module1

    Private args() As String = System.Environment.GetCommandLineArgs()
    Private fso As New Scripting.FileSystemObject

    Const STREAM = ":comment"

    Sub Main()

        Dim howto As String = "" _
            & "\n\ncomment" _
            & "\n\n    show brief help (this)" _
            & "\n\ncomment filename" _
            & "\n\n    show comment for this file" _
            & "\n\ncomment filename ""This is a comment""" _
            & "\n\n    set comment for this file"
        howto = howto.Replace("\n", vbCrLf)

        Select Case UBound(args)
            Case 1
                Console.WriteLine("comment: " & getComment(args(1)))
            Case 2
                Console.WriteLine("set comment to: " & setComment(args(1), args(2)))
            Case Else
                Console.WriteLine(howto)
        End Select

    End Sub

    Function getComment(ByVal filename As String) As String

        Dim streamname As String = filename & STREAM
 
        If fso.FileExists(streamname) Then
            getComment = fso.OpenTextFile(streamname).ReadAll
        Else
            getComment = "no comment"
        End If

    End Function

    Function setComment(ByVal filename As String, ByVal comment As String) As String

        Dim streamname As String = filename & STREAM
        fso.OpenTextFile(streamname, 2, True).Write(comment)
        setComment = comment

    End Function

End Module

Just make sure you create the project as a console app and that you add a reference to
Microsoft Scripting Runtime (C:\Windows\System32\scrrun.dll) so you can create fso. change the value of STREAM if you want your ADS to have a different name (but you must have the colon at the start of the name)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.