MathGroup Archive 1997

[Date Index] [Thread Index] [Author Index]

Search the Archive

One-liner for files?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg8203] One-liner for files?
  • From: Mark Evans <evans at gte.net>
  • Date: Mon, 18 Aug 1997 23:24:52 -0400
  • Organization: None
  • Sender: owner-wri-mathgroup at wolfram.com

I've been using Mathematica for a long time but the file system is still
very painful.

I am looking for a one-liner here.  What I want to do is input a
directory pathname as an argument, and get all the subdirectories inside
the argument folder, excluding actual data files.

It appears to me that (on Windows) it is impossible to use the form
filter a la "*.dir" because there is no suffix for directories in DOS. 
So, you have to use FileType[] to distinguish the directories from the
files in the result.  Code below.

Another thing missing in MMA is a way to let the user select a
*directory* as opposed to a *file* through the Input menu.

Mark



In[84]:=
locOfRaws = "I:\\RAWS\\"  (* Give path to original folder here *)
Out[84]=
"I:\\RAWS\\"
In[85]:=
folders = FileNames["*",locOfRaws]
types = FileType /@ folders
filtered = 
  Flatten[MapIndexed[(
          If[types\[LeftDoubleBracket]#2\[RightDoubleBracket]===
{Directory},
             {#1}, {}])&,folders]]
Out[85]=
{"I:\\RAWS\\\\DC_RAW_121796","I:\\RAWS\\\\DC_RAW_121896",
  "I:\\RAWS\\\\FM_RAW_010197","I:\\RAWS\\\\FM_RAW_010297",
  "I:\\RAWS\\\\FM_RAW_010397","I:\\RAWS\\\\FM_RAW_010497",
  "I:\\RAWS\\\\FM_RAW_011097","I:\\RAWS\\\\HV_RAW_121296",
  "I:\\RAWS\\\\HV_RAW_121396","I:\\RAWS\\\\LQ_RAW_010897",
  "I:\\RAWS\\\\LQ_RAW_010997","I:\\RAWS\\\\README.txt",
  "I:\\RAWS\\\\TK_RAW_121696"}
Out[86]=
{Directory,Directory,Directory,Directory,Directory,Directory,Directory,
  Directory,Directory,Directory,Directory,File,Directory}
Out[87]=
{"I:\\RAWS\\\\DC_RAW_121796","I:\\RAWS\\\\DC_RAW_121896",
  "I:\\RAWS\\\\FM_RAW_010197","I:\\RAWS\\\\FM_RAW_010297",
  "I:\\RAWS\\\\FM_RAW_010397","I:\\RAWS\\\\FM_RAW_010497",
  "I:\\RAWS\\\\FM_RAW_011097","I:\\RAWS\\\\HV_RAW_121296",
  "I:\\RAWS\\\\HV_RAW_121396","I:\\RAWS\\\\LQ_RAW_010897",
  "I:\\RAWS\\\\LQ_RAW_010997","I:\\RAWS\\\\TK_RAW_121696"}



  • Prev by Date: Re: Rendering image to array
  • Next by Date: Batch Jobs - Comments?
  • Previous by thread: Floor
  • Next by thread: Batch Jobs - Comments?