0
\$\begingroup\$

Task

Write some code that will walk through the entire file-system tree and collect details from file-names, folder-names, text files etc to form a tag-group. This tag group, when searched in (user input) should point to the folders they are located in.

Rules

  1. Any Language (standard libraries only).
  2. Any kind of output (should be legible).
  3. You may extend your code by reading more file-types and their metadata.
  4. Regex is allowed

You'll win

  1. +14 points for the shortest code (will be taken away when some else beats the record)
  2. +6 for each added functionality (anything you could possibly claim).
  3. -2 for each byte exceeding 1024 byte mark.

Example

Python (using os module - os.walk)

input

Enter search term below
>>> *camp*

output

Total results for *camp* = 2
-------------------------------
Camping.avi       - "C:\Users\Amelia\Videos\Summer Camping"
Campus party.avi  - "C:\Users\Public\Campus"
\$\endgroup\$
  • \$\begingroup\$ In my neighborhood, "tagging" means something very different. Anybody know how to get sharpie off my monitor? Thanks. \$\endgroup\$ – boothby Jan 6 '14 at 18:01
  • \$\begingroup\$ @boothby Sharpie? 'Round here we use spray-paint. \$\endgroup\$ – Iszi Jan 6 '14 at 18:11
  • \$\begingroup\$ @Iszi The rattle can's in my backpack, in the other room, but my sharpie was in my pocket. \$\endgroup\$ – boothby Jan 6 '14 at 19:05
14
\$\begingroup\$

BASH, 14 + 6*18 = 122

Cheap, but a win.

locate

Example:

boothby@not ~ $ locate camp
/home/boothby/Desktop/kodak/Pictures/camp.jpg
/home/boothby/Desktop/kodak/Pictures/camp2.jpg
/home/boothby/Downloads/sage-5.12/local/share/doc/networkx-1.7.dev_20131124172629/examples/graph/napoleon_russian_campaign.py
/usr/src/linux-headers-3.8.0-19/arch/arm/plat-samsung/include/plat/camport.h
/usr/src/linux-headers-3.8.0-33/arch/arm/plat-samsung/include/plat/camport.h

Feature: this is super efficient since it caches the file information in a database. The above runs on my computer in 0.187s.

... and 17 additional features:

   -b, --basename
          Match only the base name against the specified  patterns.   This
          is the opposite of --wholename.


   -c, --count
          Instead of writing file names on standard output, write the num‐
          ber of matching entries only.


   -d, --database DBPATH
          Replace the default database with DBPATH.  DBPATH is  a  :-sepa‐
          rated  list of database file names.  If more than one --database
          option is specified, the resulting path is  a  concatenation  of
          the separate paths.

          An empty database file name is replaced by the default database.
          A database file name - refers to the standard input.  Note  that
          a database can be read from the standard input only once.


   -e, --existing
          Print  only  entries  that  refer  to files existing at the time
          locate is run.


   -L, --follow
          When checking whether files exist (if the --existing  option  is
          specified),  follow trailing symbolic links.  This causes broken
          symbolic links to be omitted from the output.

          This is the default behavior.  The  opposite  can  be  specified
          using --nofollow.


   -h, --help
          Write  a summary of the available options to standard output and
          exit successfully.


   -i, --ignore-case
          Ignore case distinctions when matching patterns.


   -l, --limit, -n LIMIT
          Exit successfully after finding LIMIT entries.  If  the  --count
          option  is  specified,  the  resulting  count is also limited to
          LIMIT.


   -m, --mmap
          Ignored, for compatibility with BSD and GNU locate.


   -P, --nofollow, -H
          When checking whether files exist (if the --existing  option  is
          specified),  do not follow trailing symbolic links.  This causes
          broken symbolic links to be reported like other files.

          This is the opposite of --follow.


   -0, --null
          Separate the entries on output using  the  ASCII  NUL  character
          instead  of  writing each entry on a separate line.  This option
          is designed for interoperability with the --null option  of  GNU
          xargs(1).


   -S, --statistics
          Write  statistics  about  each  read database to standard output
          instead of searching for files and exit successfully.


   -q, --quiet
          Write no messages about errors  encountered  while  reading  and
          processing databases.


   -r, --regexp REGEXP
          Search  for  a  basic regexp REGEXP.  No PATTERNs are allowed if
          this option is used, but this option can be  specified  multiple
          times.


   --regex
          Interpret all PATTERNs as extended regexps.


   -V, --version
          Write  information  about  the  version and license of locate on
          standard output and exit successfully.


   -w, --wholename
          Match only the whole path name against the specified patterns.

          This is the default behavior.  The  opposite  can  be  specified
          using --basename.
|improve this answer|||||
\$\endgroup\$
  • 1
    \$\begingroup\$ And where is your code? \$\endgroup\$ – SergeyS Jan 6 '14 at 21:47
  • 1
    \$\begingroup\$ Right there at the top: locate \$\endgroup\$ – boothby Jan 6 '14 at 22:45
  • 7
    \$\begingroup\$ That right there is validation to a code-golfer: the solution was so small, an observer couldn't even find it. \$\endgroup\$ – boothby Jan 6 '14 at 23:13
5
\$\begingroup\$

BASH

find

A cheaper, shorter win. See @boothby answer for examples

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ Bash has always been better. :P \$\endgroup\$ – cjfaure Jan 7 '14 at 10:43
  • \$\begingroup\$ find is shorter, but locate is quicker - reminds me of my car navigation system :D \$\endgroup\$ – Yves Klett Jan 7 '14 at 16:26
2
\$\begingroup\$

C# - 200

void G(string s){foreach (var y in Directory.GetFiles(@"C:\").Where(k => k.ToLower().Contains(s.ToLower())))foreach (var f in Directory.GetDirectories(@"C:\")){Console.WriteLine(y);try{G(f);}catch{}}}
|improve this answer|||||
\$\endgroup\$
1
\$\begingroup\$

Groovy (59)

a={b-> new File("c:\\").traverse(nameFilter: ~b){print it}}

Call it with

a('test') 
|improve this answer|||||
\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.