just happens quite often that all, thought i was dead for a sec

    I'm sorta busy at work.

    WinterDragon

    Busy at work? Busy working or busy playing on the computer (I'm guilty of the latter). 😉

      Hello,

      Is there any function to read contents of a remote directory for files with specific naming scheme?

      Thanks.

      Rahul

        Hey, thanks for the response. but I'm still getting the "." and ".." directories.
        Background info, I'm putting my filenames into an array for later use.
        The problem is it's simply not inserting the "." and ".." into the array, instead it's dropping in empty data into that spot in the array.

        Any ideas? Should I just strip the 2 top elements from each array?

        Thanks

          Nah don't do that...

          just do an if statement to look...

          if_($handle_=_opendir('.'))_{
          
          ____while_(false_!==_($file_=_readdir($handle)))_{_
          
          ________if_($file_!=_"."_&&_$file_!=_".."  && $file == "fileIwant.txt")_{_
          ____________echo_"$file\n";
          ________}
          ____}
          ____closedir($handle);_
          
          }
          

          That really should work, the $file == "fileIwant.txt" you can search for it like that... or change it or whatever..

          BTW! I WAS AT WORK! And am At work, hehe Dial-Up Technical Support. 🙂

            I'm not looking to find one file among many, I need a list of all of them, so I can later open them and scoop out their inards.

            Any other ideas?

              This has always worked for me, never failed, its directly from php.net's information...

              if ($handle = opendir('.')) {
                  while (false !== ($file = readdir($handle))) { 
                      if ($file != "." && $file != "..") { 
                          echo "$file\n"; 
                      } 
                  }
                  closedir($handle); 
              }
              

              Just change the opendir('.') to the directory you want to search...

                OK, if you must make me prove it 🙂

                 $dir = "10000maniacs";
                	$artist_array = array("");
                	if ($dir_handle = opendir("$dir")) {
                    	for ($i=0; false !== ($file = readdir($dir_handle)); $i++) { 
                			print $file."<br>";
                			if ($file != "." && $file != "..") {
                				$artist_array[$i] = $file;
                				//echo "$file<br>";
                			} 
                		}
                		closedir($dir_handle);
                	}

                  for($i=0;false!==($file=readdir($dir_handle));$i++){_

                  wtf is that? hehe, if false !== ? um, first of it would be != why are you testing it with that? 2 negatives equal true btw... hehe...

                  Dunno if that will work the way you want it to... hrmmm lemme think about what you're wanting to do...

                    I hope you were seriously joking about all that because that is YOUR code if you look towards the top of the tread, hahaha.

                      Mine did not have a single for loop in it...

                      if ($handle = opendir('.')) {
                          while (false !== ($file = readdir($handle))) { 
                              if ($file != "." && $file != "..") { 
                                  echo "$file\n"; 
                              } 
                          }
                          closedir($handle); 
                      }
                      

                      Thats what I've always used... So you might be mistaking me for the other person... hrmph...

                        I understand yours didn't have the for loop, but you are still doing the double negative thing you tried to pin on me...

                        I simply replace your while statement with a for loop.

                          Hmm, interestingly enough, I believe that everytime the for loop runs, the array automatically creates an element, whether or not that code is reached (which it is not because of the if statement).

                          Weird, I'll have to work on that.

                            Well, I'll drop this up here incase somebody searches for it.
                            Here is the fix, although it's not elegent:

                            $dir = "10000maniacs";
                            $artist_array = array("");
                            
                            if ($dir_handle = opendir("$dir")) {
                            	$i=0;
                            	while (false !== ($file = readdir($dir_handle))) {
                            		if ($file != "." && $file != "..") {
                            			$artist_array[$i] = $file;
                            			$i++;
                            		}
                            	}
                            	closedir($dir_handle);
                            }
                            

                              I'm saying, I dunno if it will work in a for loop, and right now I am trying to fix the for loop in your script, or anything in there to see if it will work

                                That was the way I was going to do it, but still trying to figure out the for loop way...

                                  Actually, I just figured it, the for loop was still iterating even if an element was not added, hence the reason the data started at the 3rd element [2], so I had to by-pass the for loop so that I can reset the iterator until actual data is ready to be entered.

                                  Thanks for your help!

                                    Write a Reply...