[Date Index]
[Thread Index]
[Author Index]
Re: Chained-functional notation examples?
*To*: mathgroup at smc.vnet.net
*Subject*: [mg132709] Re: Chained-functional notation examples?
*From*: Bill Rowe <readnews at sbcglobal.net>
*Date*: Fri, 9 May 2014 02:08:07 -0400 (EDT)
*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com
*Delivered-to*: l-mathgroup@wolfram.com
*Delivered-to*: mathgroup-outx@smc.vnet.net
*Delivered-to*: mathgroup-newsendx@smc.vnet.net
On 5/7/14 at 2:44 AM, dog at gmail.com (Unknown) wrote:
>Here's a related real-live problem:
>list all files in Dir-tree:D | which are less-than daysOld:N | and
>contain "egal" in the FullPathName | and contain String:"uid" OR
>"UID"
It is not entirely clear what it is you are trying to do. There
are a couple of ways to obtain a list of files in a given directory.
First, if the directory is the current working directory, then
FileName[]
will return a list of every thing at the top level of the
directory. But in this case, only the name of things at that
level are returned not the path name.
If the directory is a subdirectory of the current working
directory you can get a list of files in that directory with
FileNames["*", dirname]
This will return a relative path name, relative to the current
working directory.
If you want the full path name then using the last form above
with dirname specified with the full path name will give you
what you want.
I will assume the desired files are in the current working
directory and you want any file with "egal" in the path name at
any sub directory level with those assumptions the problem above
can be solved as:
Cases[
Flatten@StringCases[
FileNames["*",Directory[],Infinity],___~~"egal"~~___],
_?(
FileType[#]===File &&
Subtract@@(AbsoluteTime/@{Date[][[;;3]],FileDate[#][[;;3]]}/86400)>age
&&
FindList[#,{"UID","uid"}]!={} &)]
The FileType portion filters out directories, the Subtract@@
portion computes the age of the file in days and compares that
to a specified age and the FindLIst portion looks to see if the
file contains either "UID" or "uid".
Cases checks each file for the three conditions above and only
returns a those that meet all three conditions.
Note, while this isn't a difficult thing to do in Mathematica,
if all you need to do is solve this class of problem, i.e.,
something were you need a list of files meeting a specified
criteria, Mathematica really is overkill and an expensive way to
solve this class of problem.
What Mathematica can do with files is all kinds of sophisticated
numerical analysis on the file contents, analysis that could be
very time consuming to implement in something such as Perl,
Python etc.
It makes sense to solve this class of problem within Mathematica
when you already have a license to Mathematica, are familiar
with Mathematica and solving this problem is merely a subset of
a larger problem. But it definitely does not make sense to me to
buy a license for Mathematica for just the ability to locate
files in this manner. There are far less expensive solutions for
this problem.
Another thing to consider. I've been using Mathematica since
version 1.2 and pretty much on a daily basis since version 3.0.
I consider myself quite proficient using Mathematica to solve
problems I encounter. But despite using Mathematica extensively
for quite a number of years, I do not see myself as fully
mastering Mathematica. And the level of proficiency I have
achieved was not achieved in a few days or a few weeks.
Mathematica is extremely versatile and is a very rich toolset
for solving a large variety of programs. But that versatility
comes at a price. Mathematica has what I would consider a rather
steep learning curve to climb before proficiency is achieved.
Prev by Date:
**Re: MathKernel7 produces no Graphics**
Next by Date:
**Re: DSolve test**
Previous by thread:
**Re: Chained-functional notation examples?**
Next by thread:
**mathematica modify code like?**
| |