473,508 Members | 2,255 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Manipulating files and directories..

123 New Member
Hey all..I am trying to make as script , which can import one directory called IP , take all the text files one by one from that directory , and then can give me (using pregmatch or something ) Hostname from each file...
Code is below..
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  $dirname = "/home/ajd/IP";
  3. if($handle = opendir($dirname))
  4. while(false !== ($filename = readdir($handle))){
  5. echo $filename;
  6. $lines = file($filename);
  7. foreach($lines as $line_num)
  8. {
  9. print_r($lines);
  10. //$var = preg_match('/Host Name(.*)/',$matches);
  11. //print_r($matches);
  12.  }
  13. }
  14. closedir($handle);
  15. ?>
  16.  
The above code gives me all the file names in the directory in which I am writing script (i.e home/ajd/data/ip.php
It gives me list of files and directories in data directory...
Please help out..
Thanks
Jul 11 '08 #1
1 1170
pbmods
5,821 Recognized Expert Expert
Heya, ajd.

Try using glob() (http://php.net/glob).
Jul 11 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
1970
by: Tum | last post by:
Hi folks, I've been trying to make a decision and it's driving me crazy. Is a directory a file or is a directory NOT a file but a node? Should I have A)
44
3992
by: Xah Lee | last post by:
here's a large exercise that uses what we built before. suppose you have tens of thousands of files in various directories. Some of these files are identical, but you don't know which ones are...
10
9893
by: TokiDoki | last post by:
Hello there, I have been programming python for a little while, now. But as I am beginning to do more complex stuff, I am running into small organization problems. It is possible that what I...
4
7553
by: Jerry | last post by:
I'm having just a bit of trouble wrapping my brain around the task of working with folders that are above the site's root folder. I let users upload photos (.jpg/.gif files) which can...
5
655
by: rbt | last post by:
What is the most efficient way to recursively remove files and directories? Currently, I'm using os.walk() to unlink any files present, then I call os.walk() again with the topdown=False option...
4
4190
by: rn5a | last post by:
I have a ListBox which should list all the files & directories that exist in a particular directory. The problem is I can get the ListBox to list either all the files or all the directories but not...
2
2656
by: Alan Bak | last post by:
HI I am running Active Perl on a Windows XP machine. I am hoping to get some advise on a strategy to monitor and copy files that are arriving in a directory and need to be copied to a second...
3
1474
by: woete | last post by:
I'd like to obtain an image's width and height. I find interesting articles on several sites... However, all these scripts only work with images that are stored locally. Can you give any hint on...
0
862
by: Thomas | last post by:
Hi all, I want to manipulate sys.path outside of PYTHONPATH (environment) and sys.path.append() (programmatically). A bit of background: We're maintaining a small application that includes a...
0
7229
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7398
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5637
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4716
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3194
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1566
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.