Cannot delete folder

I am new user. I try to deploy my website. my domain is pvt.info.nf .
I have a problem on the File Manager. I cannot delete 1 incorrect directory. The directory is automatically created. the error message is :

Error during FTP change directory, at “htdocs/C:\TA\laragon\www\PVTInfo\storage\logs” : Unable to change directory (path: /htdocs/C:\TA\laragon\www\PVTInfo\storage\logs)

I tried to delete it from file manager and use a FTP Client ( FileZilla ), but both failed. the directory has an invalid Windows-based path (C:\...), and the FTP client is unable to access or delete it due to server restrictions.

Can you help me to delete it ?

Hi and welcome to the forum

Edit code/path to reflect the file/folder you want to delete

4 Likes

I already follow the method.
I create a php file in my local machine called deletefile.php. Then I pull and put it on the same folder as the incorrect " htdocs/C:\TA\laragon\www\PVTInfo\storage\logs " directory.
I run the deletefile.php on my browser :

http://pvtinfo.free.nf/deletefile.php

Unfortunately, the system tells me " unable to delete file ". the incorrect directory couldn’t be deleted.

I should tell that I put both deletefile.php and the incorrect directory in the htdocs folder in my account’s file manager

you need to delete everything, not just the last folder/file

delete this “C:\TA”

because it is the root folder for everything inside and none of them will work because the path is invalid because it contains a backslash.

If it doesn’t work out that way, maybe we’ll come up with something


Also please show us your code you used

copy and paste it and then select code and format it as code here

image

4 Likes

Firstly, sorry for taking so long to respond. I’ve just woken up.
Here is the code from deletefile.php :

<?php

if (unlink('htdocs/C:\TA\laragon\www\PVTInfo\storage\logs',)){
    echo "File deleted!";
}else{
    echo " unable to delete file";
}

I

Try to remove htdocs/ from the path, as you should be supposed to put that file inside your htdocs folder, and see if it works.

2 Likes

I remove htdocs/ from the deletefile.php codes :

<?php

if (unlink('C:\TA\laragon\www\PVTInfo\storage\logs',)){
    echo "File deleted!";
}else{
    echo " unable to delete file";
}

But my website still unable to delete the incorrect file

can the infinityfree support team manually delete the incorrect directory from their side ? I already tried to delete and rename it using PHP codes, already tried to delete it using FileZilla FTP application. But nothing worked

This situation is a little bit more difficult than the previous cases. Those cases only involved a single file, this involves a directory with more files in them.

I see you have an updated deletefile.php script that seems like it should do the trick and recursively delete all files.

The only issue I see is the directory:

image

The directory to delete is just the name of the directory to delete. No htdocs before it, and also no whitespace characters.

If you change that, I don’t see any reason why your current script doesn’t work.

2 Likes

I try to delete the incorrect directory using this codes and run it using http://pvtinfo.free.nf/deletefile.php. this is what I made :

<?php

if (unlink('C:\TA\laragon\www\PVTInfo\storage\logs',)){
    echo "File deleted!";
}else{
    echo " unable to delete file";
}

but the website still shows " unable to delete file ".
are there any other methods to solve this problem ?

That code doesn’t work. unlink can only delete files, not directories.

The current deletefile.php on your account is a lot more sophisticated. It actually traverses the directories using scandir and recursively deletes all files with unlink and all directories with rmdir.

The logic itself looks excellent. The only flaw I see is the input directory being invalid.

3 Likes

you are right. now the incorrect directory is successfully deleted.
Here is the code that I use in deletefile.php :

<?php
$dir = 'C:\TA\laragon\www\PVTInfo\storage\logs'; // Use the actual path from your file manager

function deleteDir($dir) {
    if (!is_dir($dir)) {
        return false;
    }

    $objects = scandir($dir);
    foreach ($objects as $object) {
        if ($object != "." && $object != "..") {
            if (is_dir($dir . "/" . $object)) {
                deleteDir($dir . "/" . $object);
            } else {
                unlink($dir . "/" . $object);
            }
        }
    }
    return rmdir($dir);
}

if (deleteDir($dir)) {
    echo "Directory deleted successfully.";
} else {
    echo "Failed to delete the directory.";
}
?>

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.