Jump to content

How To Get Files/directories Within A Selected Direcotry?


Recommended Posts

Hello to the people of HelioHost.

 

After a long time of using your service, this is the first time I've decided to actually brighten up my dull brain.

 

My question is simply (hopefully understandable). I am trying to write a script that enables me to read in files and directories from sub folders and then read in the data from them.

 

Many thanks in advance.

Link to comment
Share on other sites

Hello,

I found this function on the web which permits you to list all the files in a specific directory and its sub-directories.

 

function ListFiles($dir) {
   if($dh = opendir($dir)) {
    $files = Array();
    $inner_files = Array();
    while($file = readdir($dh)) {
	    if($file != "." && $file != ".." && $file[0] != '.') {
		    if(is_dir($dir . "/" . $file)) {
			    $inner_files = ListFiles($dir . "/" . $file);
			    if(is_array($inner_files)) $files = array_merge($files, $inner_files);
		    } else {
			    array_push($files, $dir . "/" . $file);
		    }
	    }
    }
    closedir($dh);
    return $files;
   }
}

 

And here's how to use it:

 

foreach (ListFiles('YOUR-DIRECTORY') as $key=>$file){
   echo $file ."<br />";
}

 

I hope it helps.

Link to comment
Share on other sites

Here's a site serach I made awhile back using RecursiveDirectoryIterator and posted somewhere in this forum:

 

http://byrondallas.heliohost.org/helio/site_search.txt

 

Just upload it to your site and rename it with a .php extension. To search for a file it goes like this:

 

Searching for a file named white_rose.jpg. Enter rose as the file name and any files with the name rose will show up in the results. To show all files that end in php enter .php as the file. To show ALL files in a directory, enter a . (dot). The check box that says Stop recursive means to keep it from searching in subdirectories.

 

Link to comment
Share on other sites

wow.

 

Thanks so much for your answers :)

 

It's not exactly a project Jairy DJ. I'm just trying to get certain files out of the file system. Truth be told, I'm not very good at php or any other coding language except VB but idk how to apply VB on a website.

Link to comment
Share on other sites

wow.

 

Thanks so much for your answers :)

 

It's not exactly a project Jairy DJ. I'm just trying to get certain files out of the file system. Truth be told, I'm not very good at php or any other coding language except VB but idk how to apply VB on a website.

 

It's not a hard task to setup a vb script, there are lots of tuts on the web and I can help you too if you encountered any trouble.

Good luck!

Link to comment
Share on other sites

  • 4 weeks later...

VBscript is a client-side language that only works in Internet Explorer, thus wouldn't be much use for what you are trying to do here. To add a VBscript to your webpage, use:

<script type="text/vbscript">
'Your code here
</script>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...