life-cycle.de

maintained and written by Klement J Fellner

Delete directory with special character (umlaut, etc.)

German: Löschen eines Verzeichnisses mit Sonderzeichen (Umlaute, ÿ, …)

I once made a big mistake and allowed anonymous FTP on my web hosting. It was only for a short period (under one day) but it was enough to fill the space on my disk. Even worse, the directory with all the content was named “    ÿagged.by.nnnn”.

If I had access to my hosting via telnet or ssh a remove using inode information would have done the job. But my hoster does only allow FTP access.

After some searching on the web I found a perl script that did the job (see here).


#!/usr/local/bin/perl   // CHECK the location of perl on your server, e.g. /usr/bin/perl

cleanup("/aftp/dfd");  // give the full path to the directory you want to start the process

sub cleanup {
        my $dir = shift;
    local *DIR;

    opendir DIR, $dir or die "opendir $dir: $!";
    my $found = 0;
    while ($_ = readdir DIR) {
            next if /^\.{1,2}$/;
            my $path = "$dir/$_";
        unlink $path if -f $path;
        cleanup($path) if -d $path;
    }
    closedir DIR;
    rmdir $dir or print "error - $!";
}

Save the file as “remove_directory.cgi”

Place the script into a directory on your server. Open up your favorite web browser and enter the address to the script.

If you get a 404 (file not found) your address in the browser is wrong.

If you get a 500 (Internal server error) this may have different causes:

  1. The perl interpreter can not be found.
    Solution: Check the first line of the script (Hint: check already existing perl scripts on your server for the location or the FAQ of your provider).
  2. The script is not executable. Solution: chmod 755 (if you use a ftp client like smartftp right-click the file to do this change.
  3. The script may include DOS CR/LF if you edit the file on Windows/DOS. Solution: use a modern editor to save the file with Unix LF or create the file on Linux/Unix. Free editor that can do the trick: PSPad.
  4. I had a third problem: I uploaded the file in text mode. If nothing helps, try to upload the file as binary.

Hope this helps. For me the script ended with an error but deleted everything beneath the given directory.

Powered by ScribeFire.

Schreibe einen Kommentar

Du musst angemeldet sein, um einen Kommentar schreiben zu können.