473,320 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

how to find files

Hit here,

I am looking for an example how to select a or several files.

I have a directory with a bunch of files. Now I want to use a form which
allows me to enter some words which will be used to select files containing
those words.

Do you have any idea?

Regards
Bruno
Jul 17 '05 #1
1 1806
bruno storz wrote:
I have a directory with a bunch of files. Now I want to use a form which
allows me to enter some words which will be used to select files containing
those words.


grep
1. get the words into an array
2. grep foreach word in the files in the directory
3. show results

#v+

<?php
$filespec = '/var/www/htdocs/datadir/*';

// 1
$words = array('word1', 'word2');

// 2
$oneword = '';
foreach ($words as $word) {
$oneword .= `grep -li $word $filespec`;
}
$oneword = explode("\n", $oneword);
$files = array_count_values($oneword);

// 3
foreach ($files as $file+>$dummy) {
echo $file, "<br/>\n";
}
?>

#v-
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: hokiegal99 | last post by:
How do I say: x = string.find(files, 'this', 'that', 'the-other') currently I have to write it like this to make it work: x = string.find(files, 'this') y = string.find(files, 'that') z =...
10
by: hokieghal99 | last post by:
import os, string print " " setpath = raw_input("Enter the path: ") def find_replace(setpath): for root, dirs, files in os.walk(setpath): fname = files for fname in files: find =...
5
by: Richard Wesley | last post by:
I am using coverage.py to run my unit test suite to check for missing tests. It mostly works, but for some mysterious reason, some of the files can't be found because they are not in the same...
1
by: Xah Lee | last post by:
suppose you want to do find & replace of string of all files in a directory. here's the code: ©# -*- coding: utf-8 -*- ©# Python © ©import os,sys © ©mydir= '/Users/t/web'
1
by: Dan Jones | last post by:
I'm writing a script to process a directory tree of images.  In each directory, I need to process each image and generate an HTML file listing all of the images and links to the subdirectories....
1
by: Xiangliang Meng | last post by:
Hi, all. Recently, I find there is a way in our project to maintain a global set in many files by using preprocessing directives. I'm wondering if we could find a better method for this. Many...
2
by: Rosa | last post by:
Hi, I'm looking for an elegant solution on how to find the youngest file within a given directory. At the moment I'm storing all files in an array and loop through it comparing the creation date...
0
by: Xah Lee | last post by:
Interactive Find and Replace String Patterns on Multiple Files Xah Lee, 2006-06 Suppose you need to do find and replace of a string pattern, for all files in a directory. However, you do not...
2
by: graphicsxp | last post by:
Hi, How can I open all the files in a directory, which names match a particular string ? Say I have a string like 'a file name to find' and I want to find and open all the files of a given...
2
by: Olumide | last post by:
Hello, I've got this nice inner class that I'm holds a set of "FrontPoint" objects as shown below. Unfortunately, the find and insert methods trigger massive C2784 errors. Would someone please...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.