Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 89771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:46:07+00:00 2026-05-10T22:46:07+00:00

How would one go about deleting all of the directories in a directory tree

  • 0

How would one go about deleting all of the directories in a directory tree that have a certain name if the only access to the server available is via FTP?

To clarify, I would like to iterate over a directory tree and delete every directory whose name matches a certain string via FTP. A way to implement this in PHP would be nice – where should I start? Also, if anyone knows of any utilities that would already do this, that would be great as well.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T22:46:08+00:00Added an answer on May 10, 2026 at 10:46 pm

    Here is a starting point- a function that will scan through an FTP directory and print the name of any directory in the tree which matches the pattern. I have tested it briefly.

    function scan_ftp_dir($conn, $dir, $pattern) {     $files = ftp_nlist($conn, $dir);     if (!$files) {         return;     }      foreach ($files as $file) {         //the quickest way i can think of to check if is a directory         if (ftp_size($conn, $file) == -1) {              //get just the directory name             $dirName = substr($file, strrpos($file, '/') + 1);              if (preg_match($pattern, $dirName)) {                 echo $file . ' matched pattern';             } else {                         //directory didn't match pattern, recurse                    scan_ftp_dir($conn, $file, $pattern);             }         }      } } 

    Then do something like this

    $host = 'localhost'; $user = 'user'; $pass = 'pass';   if (false === ($conn = ftp_connect($host))) {     die ('cannot connect'); }  if (!ftp_login($conn, $user, $pass)) die ('cannot authenticate');   scan_ftp_dir($conn, '.', '/^beginswith/'); 

    Unfortunately you can only delete an empty directory with ftp_rmdir(), but if you look here there is a function called ftp_rmAll() which you could use to remove whole directory structures which you find.

    Also I have only tested on Unix the trick of using the fail status returned from ftp_size() as a method of checking if an item returned by ftp_nlist() is a directory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 66k
  • Answers 66k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer If you don't want to use precompiled headers, then there… May 11, 2026 at 11:33 am
  • added an answer Signals and slots across threads found on the start page… May 11, 2026 at 11:33 am
  • added an answer You can't bind an array to an SQL parameter. You… May 11, 2026 at 11:33 am

Related Questions

How would one go about deleting all of the directories in a directory tree
How would one go about displaying taskbar notifications? I want to write an app
How would one go about profiling a few queries that are being run from
How would one go about adding a submenu item to the windows explorer context
How would one go about loading compiled C code at run time, and then
How would one go about linking (some) symbols to specific fixed addresses using GNU
Given a table (mytable) containing a numeric field (mynum), how would one go about
As a programmer I have no idea how one would go about programming menus
How would one display any add content from a dynamic aspx page? Currently I
How would one configure trac to allow anonymous submission of tickets?

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.