none
add tag to a file

Răspunsuri

  • tx file (as many others) dont support any kind of tags or something similar what so ever. But you can do some work-around to make it by your own.

    I would suggest you to put the tag into the beginning of time file (so on top), and use some standards, so you will know how to write and more importanty, how to read. Find out a uniqe way of creating your own tag, like pasting text into square brackets, thats how you will know (when reading file), that this is a tag.

    Example:

    the beginning of the file:

    [date:5.1.2012] [creationTime:5.11pm] [someTytle:someData] text....

    So now when you will read the file, you exactly know that tag is all whats in square brackets. Here is how you will read it:

    Dim [date] As String = ""
    Dim creationTime As String = ""
    someType = ""
    Dim lines As List(Of String) = List(Of String)()
    Dim sr As New StreamReader("filePath")
    Dim line As String
    While (InlineAssignHelper(line, sr.ReadLine())) IsNot Nothing
    	lines.Add(line)
    End While
    
    For i As Integer = 0 To lines.Count - 1
    	'tags:
    	If line.StartsWith("[") AndAlso line.EndsWith("]") Then
    		Select Case i
    			Case 0
    				[date] = lines(i)
    				Exit Select
    			Case 1
    				creationTime = lines(i)
    				Exit Select
    			Case 2
    				someType = lines(i)
    				Exit Select
    		End Select
    	Else
    		Exit For
    		'if you only want to read tags, else you can erase this else statement
    	End If
    Next

    To help you more, is some tag there is a description and its value. To get the value only, you can simply use Split method by colon (regarding my example), and what is in index 1 this is the value (in index 0 there is a description).

    Like:

    Dim data As String() = lines(i).Split(":"C)
    Select Case i
    	Case 0
    		[date] = data(1)
    		Exit Select
    	Case 1
    		creationTime = data(1)
    		Exit Select
    	Case 2
    		someType = data(1)
    		Exit Select
    End Select


    You can see I created my own custom tag(s), and I can read then my own way (with some standardization of course - it cannot be all dynamic), and it works fine. If this is what you`ve meant, then it can serve you well.

    hope it helps,

    bye


    Mitja




    1 mai 2012 15:28

Toate mesajele

  • What kind of file, what tag EXACTLY? Tell us more.

    Mitja

    30 aprilie 2012 10:56
  • it's a simple txt file.

    I create the file, do some modifications, save the file and I want to add a tag to the file too. For another reasons it's not good to store the tag directly in the file.

    Under tag I mean a file property like date of creation, etc. I don't know, if windows supports this.

    30 aprilie 2012 17:33
  • Hi DerStauner,

    Welcome to the MSDN forum.

    As far as I know, the txt file doesn’t support to add the tags. Please check this article:

    Add tags or other properties to a file: http://windows.microsoft.com/en-us/windows-vista/Add-tags-or-other-properties-to-a-file

    You cannot add or modify the file properties of some types of files. For example, you can add or modify the properties of Microsoft Office documents and Searches, but you can't add or modify the properties of TXT or RTF files.

    Hope this helps.


    Mark Liu-lxf [MSFT]
    MSDN Community Support | Feedback to us

    1 mai 2012 05:07
    Moderator
  • tx file (as many others) dont support any kind of tags or something similar what so ever. But you can do some work-around to make it by your own.

    I would suggest you to put the tag into the beginning of time file (so on top), and use some standards, so you will know how to write and more importanty, how to read. Find out a uniqe way of creating your own tag, like pasting text into square brackets, thats how you will know (when reading file), that this is a tag.

    Example:

    the beginning of the file:

    [date:5.1.2012] [creationTime:5.11pm] [someTytle:someData] text....

    So now when you will read the file, you exactly know that tag is all whats in square brackets. Here is how you will read it:

    Dim [date] As String = ""
    Dim creationTime As String = ""
    someType = ""
    Dim lines As List(Of String) = List(Of String)()
    Dim sr As New StreamReader("filePath")
    Dim line As String
    While (InlineAssignHelper(line, sr.ReadLine())) IsNot Nothing
    	lines.Add(line)
    End While
    
    For i As Integer = 0 To lines.Count - 1
    	'tags:
    	If line.StartsWith("[") AndAlso line.EndsWith("]") Then
    		Select Case i
    			Case 0
    				[date] = lines(i)
    				Exit Select
    			Case 1
    				creationTime = lines(i)
    				Exit Select
    			Case 2
    				someType = lines(i)
    				Exit Select
    		End Select
    	Else
    		Exit For
    		'if you only want to read tags, else you can erase this else statement
    	End If
    Next

    To help you more, is some tag there is a description and its value. To get the value only, you can simply use Split method by colon (regarding my example), and what is in index 1 this is the value (in index 0 there is a description).

    Like:

    Dim data As String() = lines(i).Split(":"C)
    Select Case i
    	Case 0
    		[date] = data(1)
    		Exit Select
    	Case 1
    		creationTime = data(1)
    		Exit Select
    	Case 2
    		someType = data(1)
    		Exit Select
    End Select


    You can see I created my own custom tag(s), and I can read then my own way (with some standardization of course - it cannot be all dynamic), and it works fine. If this is what you`ve meant, then it can serve you well.

    hope it helps,

    bye


    Mitja




    1 mai 2012 15:28
  • @DerStauner

    The speciality of a txt file is that it is simple.

    Most files contain tags. But txt files don't to keep it simple possible to use it almost everywhere. If you violate that the sense of a text file is nothing.

    If there would be tags needed then a binary file would be obvious. 

    http://msdn.microsoft.com/en-us/library/system.io.binaryreader.aspx

    http://msdn.microsoft.com/en-us/library/system.io.binarywriter.aspx


    Success
    Cor

    1 mai 2012 15:38
  • If you are targeting NTFS with your application then you could take advantage of windows meta data (or NTFS Alternate Data Streams).

    Here are a few links which might help (you can find more too by searching the Internet):

    http://www.dreamincode.net/forums/topic/145671-use-safe-file-handles-to-access-alternate-data-streams/

    http://www.codeproject.com/Articles/9387/Manipulate-Alternate-Data-Streams

    http://www.vbforums.com/showthread.php?t=354205

    This may change in Windows 8, but if it does it should provide more functionality/easy of use.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    1 mai 2012 16:19
    Moderator
  • hi,

    thanks for all your comments.

    I think, I will make a custom file tag as Mitja Bonca wrote.

    1 mai 2012 16:45
  • hi,

    thanks for all your comments.

    I think, I will make a custom file tag as Mitja Bonca wrote.

    Just keep in mind that this is not what you asked for... this solution is modifying the data of the file itself so this is not a "tag" solution, but rather just a file-header solution.  The "extra data" could be modified/corrupted by a user with just Notepad.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    1 mai 2012 16:58
    Moderator