thanks the format works, i have written some code for deleting some lines from the above obtained files,i have used like keyword match for deleting lines from the above files.the keywords are in the array. can u pls look at the code and check where goes wrong. <? $del_lines=array("[","TYP","P_MPP","I_MPP","V_MPP","T=","FIT","INTENSITAET"); $dir=getcwd(); $handle = opendir($dir); while (false !== ($file = readdir($handle))) { if ((preg_match('/^2005\d{4}_\d{4}\.txt$/', $file))||(preg_match('/^2005\d{4}_\d{4}\_01_01\.txt$/',$file))){ $fc=file($file); // for reading $f=fopen($file,"w"); // for writing. foreach($fc as $line){ for($i=0;$i<sizeof($del_lines);$i++){ if(!strstr($line,$del_lines[$i])) fputs($f,$line); } } fclose($f); } } closedir($handle); ?> Stut <stuttle@xxxxxxxxx> wrote: babu wrote: > I have a directory which has thousands of files based on date. > for example > yyyymmdd-number(auto increment).txt > 20050101-0001.txt,20050101-0002.txt............................20050101-0210.txt > 20050102-0001.txt,20050102-0002.txt..............................20050102-0141.txt > > and many other files, but i want to extract data from the files with the above format. > > I have seen in the php documentation for reading a directory,but not files with a specific structure.i could not able to write the correct regular expression for the filename match. > can some one give an idea. Check out http://php.net/glob. This might not be the best way to do it if you have *lots* of files since it returns all matches in an array. A regex to match might look something like \d\d\d\d\d\d\-\d\d\d\d\.txt but I'm no regex expert. -Stut --------------------------------- How much free photo storage do you get? Store your holiday snaps for FREE with Yahoo! Photos. Get Yahoo! Photos