add tag to a file
-
30 апреля 2012 г. 8:17
Hi,
how can I add a tag to a file? Not at the time of the creation, but later.
Все ответы
-
30 апреля 2012 г. 10:56
What kind of file, what tag EXACTLY? Tell us more.Mitja
- Предложено в качестве ответа Cor LigthertMVP 30 апреля 2012 г. 14:13
-
30 апреля 2012 г. 17:33
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.
-
1 мая 2012 г. 5:07Модератор
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
- Предложено в качестве ответа Cor LigthertMVP 1 мая 2012 г. 7:46
-
1 мая 2012 г. 15:28
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
- Изменено Mitja BoncaMicrosoft Community Contributor 1 мая 2012 г. 15:36
- Помечено в качестве ответа DerStauner 1 мая 2012 г. 16:43
-
1 мая 2012 г. 15:38
@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 мая 2012 г. 16:19Модератор
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.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 мая 2012 г. 16:45
hi,
thanks for all your comments.
I think, I will make a custom file tag as Mitja Bonca wrote.
-
1 мая 2012 г. 16:58Модератор
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"

