UPDATES VIA   RSS  |  Email Get updates via feedburner Get updates via twitter
Home / Coding / PHP / PHP: Get all files and folde…

PHP: Get all files and folders from a directory (folder)

Posted on 16. Jun, 2009 by in Coding, PHP

To get all files and folders from a directory (folder) I found scandir to be the perfect solution.

scandir scans a directory and returns an array containing all files and directories under the parent directory we’re looking in.

The code below will try to remove a directory, if the element is a directory or delete a file, if respectively the element is a file.

$lookin='./home/folder';
$elements=scandir($lookin);
foreach($elements as $singleEl) {
     if(is_dir($lookin.'/'.$singleEl)) rmdir($lookin.'/'.$singleEl);
     else
     unlink($lookin.'/'.$singleEl);
}
Translate this post
                    
                    

Related posts:

  1. Apache & ModRewrite: How to easily deny access to a folder with htaccess
  2. JavaScript: How to get the index (position within a group) of an object with jQuery?
  3. JavaScript: Where do I Find All Properties for All HTML Elements ?
  4. PHP: How to get creation time of file with PHP on Linux machines
  5. WordPress: Best SEO iTranslator for WordPress, get free traffic from fully automated plugin script

  • http://www.clockstyle.ru Wayne

    А зачем их получать оттудова?

  • Hakankara

    Tüm
    dünyadaki okey oyuncuları ile aynı platform içerisinde sohbet ederek canlı okey
    oynamaya hazır olun. http://www.okey-oyna.com sizi eğlenceye ve heyecana davet ediyor. İnternette görüntülü
    olarak okey oyna, gerçek kişilerle tanış, turnuva
    heyecanını yaşa. Dünyanın en büyük internet oyun portalı içerisine kayıt olun
    ve oynamaya hemen başlayın.