Adding tags to file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
batchcc
Posts: 139
Joined: 17 Aug 2015 06:05
Contact:

Adding tags to file

#1 Post by batchcc » 05 Jul 2016 16:21

Hi everyone I have spent some time googling how to add tags to a file with a batch script / cmd and have found no solution does any one know how to do this thanks.

ShadowThief
Expert
Posts: 1160
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Adding tags to file

#2 Post by ShadowThief » 05 Jul 2016 17:30

Tags?

batchcc
Posts: 139
Joined: 17 Aug 2015 06:05
Contact:

Re: Adding tags to file

#3 Post by batchcc » 06 Jul 2016 05:24

ShadowThief wrote:Tags?

http://www.techrepublic.com/blog/window ... windows-7/

In a recent Windows Desktop Report, "Take Advantage of Search Filters in Windows Explorer," I showed you how to use and take advantage of the Search filters built in to Windows Explorer's Search box in Windows 7. As I told you in that blog post, as soon as you begin typing text in the Search box, Windows immediately begins sifting through the search index for that text in folder names, file names, the contents of the file, and file properties, such as Tags. I also showed you how you can narrow your search by creating your own filters based on file properties such as Tags.

In my example, I showed you that if you wanted to find files that have Invoice in the Tag, you can use the Tag: filter by typing the following in the Search box:

Tag:Invoice

Since that blog was posted, I have received several emails from readers asking how you go about tagging files so that you can search on Tags.

penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Adding tags to file

#4 Post by penpen » 17 Jul 2016 05:51

The above link does not explain which type of tags are used or how they are stored:
EXIF, XMP, ... .

I don't have Windows 7 and it seems i can't add tags in windows 10 (there are fields listed for EXIF, but this doesn't prove anything).
If it is EXIF then the exif tool may help:
http://www.sno.phy.queensu.ca/~phil/exiftool/faq.html


penpen

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Adding tags to file

#5 Post by Aacini » 17 Jul 2016 09:39

The article at that link is very clear:

Greg Shultz article wrote:Tagging files as you save them

When you save files from within certain applications, you'll have the opportunity to Tag your files. For example, Word 2007's Save As dialog box provides you with the ability to Tag a file. In fact, all Microsoft Office 2007 applications will allow you to add Tags from the Save As dialog box.

Tagging files from the Properties dialog box

You can Tag a file from within its Properties dialog box. Again, keep in mind that not all file types can be tagged.

To do so, just right-click on the file and select the Properties command. When the Properties dialog box appears, select the Details tab. If the file type can be tagged, you'll find the Tags property.

Tagging files from within Windows Explorer

You can also tag a file from within Windows Explorer. Again, keep in mind that not all file types can be tagged.

When you select a file that can be tagged, you'll see the Tags property in the Details pane at the bottom of the folder window, as shown in Figure D. You'll discover that you can add multiple Tags if you wish and you can see a list of recently used Tags.


Are you asking how to open a dialog box in Microsoft Office or Windows Explorer and change the value of the Tag field via a Batch file?

Otherwise I am afraid I don't understand what you mean in your question...

Antonio

douglas.swehla
Posts: 75
Joined: 01 Jun 2016 09:25

Re: Adding tags to file

#6 Post by douglas.swehla » 27 Jul 2016 05:11

You can use alternate data streams (ADS) for a homebrew tagging solution. You can think of them as hidden files attached to normal files. See https://blogs.technet.microsoft.com/askcore/2013/03/24/alternate-data-streams-in-ntfs/ for a more detailed discussion of what they are and how to use them.

Pros:
  • You can use it on file types that don't natively support tagging.
  • You have a lot of discretion in how to organize your tags:
    • each tag as an ADS file name; file has no content, e.g. file "vacation" is empty
    • treat file name and content as a key/value pair: file "destination" contains content "Aruba"
    • have a single "tags" file containing all tags. Arrange as delimited list or one per line. Lines can contain key/value pairs: destination=Aruba

Cons:
  • The tags don't appear in the Tags column in Windows Explorer.
  • ADS can only exist on NTFS file partitions
    • They won't survive being copied to an OS X or Linux drive, or most USB drives.
    • They may not survive being sent over internet (email, chat, posting), depending on the server types encountered in transit.

The article recommends either Powershell or the downloadable streams.exe utility for manipulating these files. If you prefer a pure batch approach, here are some methods:

Code: Select all

@echo off

:create
:: overwrite existing file
echo Main file > tagged.txt
echo semicolon;delimited;list > tagged.txt:tags
echo extension is optional > tagged.txt:tags.txt

:update
:: append to existing file
echo comma,delimited,list >> tagged.txt:tags
(for /l %%I in (1,1,100) do @echo tag%%I) >> tagged.txt:tags.txt

:read
rem :: Send file content to console
type tagged.txt

rem :: fails. TYPE can't find ADS
type tagged.txt:tags
type tagged.txt:tags.txt

rem :: works. MORE outputs one screenful at a time.
rem :: Press spacebar to advance one screen, or Enter to advance one line.
more< tagged.txt:tags
more< tagged.txt:tags.txt

rem :: works. FOR outputs each line of whole file.
for /f "tokens=* delims=" %%F in (tagged.txt:tags) do @echo %%F
for /f "tokens=* delims=" %%F in (tagged.txt:tags.txt) do @echo %%F

:edit
rem :: Use text editor of your choice.
start notepad tagged.txt
start notepad tagged.txt:tags
start notepad tagged.txt:tags.txt

:search
rem :: Find lines with tag in known ADS.
(more< tagged.txt:tags) | find "comma"
for /f "tokens=* delims=" %%F in (tagged.txt:tags) do @echo %%F | find /i "comma"

rem :: Find single tag in known ADS.
for /f "tokens=* delims=" %%F in (tagged.txt:tags) do (
   for %%A in (%%F) do @echo %%A
) | find /i "comma"

rem :: Find name of ADS containing some tag.
for /f "tokens=1* delims= " %%F in ('dir /r ^| find "$DATA"') do (
   for /f "tokens=* delims=" %%A in (%%G) do @echo %%A | find /i "delimited" >nul && echo %%G
)

:delete
rem :: You can't delete individual ADS files directly.
rem :: These commands result in a syntax error.
del tagged.txt:tags
del tagged.txt:tags.txt

rem :: Best you can do is clear their contents.
echo\ > tagged.txt:tags
echo\ > tagged.txt:tags.txt

rem :: The ADS files are deleted when the main file is.
del tagged.txt
dir /r tagged*

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Adding tags to file

#7 Post by Aacini » 27 Jul 2016 09:15

As I said in my reply, the OP should clear what exactly he wants; I don't think the ADS different solution be what the OP was looking for...

Anyway, in this link there is another description of ADS (and other ways to use it).

Antonio

douglas.swehla
Posts: 75
Joined: 01 Jun 2016 09:25

Re: Adding tags to file

#8 Post by douglas.swehla » 27 Jul 2016 09:39

Aacini wrote:As I said in my reply, the OP should clear what exactly he wants; I don't think the ADS different solution be what the OP was looking for...

Yes, OP should, and I expect you're right. I just think ADS are neat, and haven't seen them talked about much, and this seemed like a good opportunity.

Aacini wrote: Anyway, in this link there is another description of ADS (and other ways to use it).

Looks like you think they're neat, too. Hopefully someday they'll be more dependable.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Adding tags to file

#9 Post by foxidrive » 27 Jul 2016 12:09

douglas.swehla wrote:Hopefully someday they'll be more dependable.


That was the problem with them many years go too. Some defrag tools wiped all the ADS.

mirrormirror
Posts: 129
Joined: 08 Feb 2016 20:25

Re: Adding tags to file

#10 Post by mirrormirror » 27 Jul 2016 22:33

FYI, the newer versions of 7-zip are ADS aware and can archive them in certain types of archives - search for "streams" in the histoory log:
[url]http://www.7-zip.org/history.txt[/url]

Post Reply