Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove a symlink with PHP on Windows

How do I remove a symlink with PHP on windows?

Running this:

mkdir('test');
symlink('test', 'test2');
unlink('test2');

Gives the following error:

PHP Warning:  unlink(test2): Permission denied in C:\path\to\app\testlink.php on line 4
PHP Stack trace:
PHP   1. {main}() C:\path\to\app\testlink.php:0
PHP   2. unlink() C:\path\to\app\testlink.php:4

The directory and symlink were made correctly, just not removed.

Running:

  • PHP 5.4.9 (CLI)
  • Windows 8
like image 765
Petah Avatar asked Aug 15 '13 21:08

Petah


People also ask

How do I remove a symbolic link in Windows?

To delete a symbolic link, treat it like any other directory or file. If you created a symbolic link using the command shown above, move to the root directory since it is "\Docs" and use the rmdir command. If you created a symbolic link (<SYMLINK>) of a file, to delete a symbolic link use the del command.

How do I remove a symlink?

Remove a Symbolic Link using the rm command You can also use the -i flag with the rm command to prompt for confirmation. After that, you can use the ls -l command to confirm if the symlink has been removed. That is all there is to it!

Is symlink PHP?

The symlink() function in PHP is an inbuilt function which is used to create a symbolic link for a target which already exists. It helps to create a specific name link for a target. The target and link names are sent as parameters to the symlink() function and it returns True on success and False on failure.

What happens when you delete a symlink?

The symbolic link does not contain any data, but you can perform all operations on the symbolic link file. Removing a symbolic link does not delete the original file, but deleting a file makes the symlink a dangling link. In this guide, we will learn how to remove symbolic links using unlink and rm commands.


1 Answers

Ok, I figured it out. So Ill leave this here for future reference:

To remove a symlink to a directory use the rmdir function:

mkdir('test');
symlink('test', 'test2');
rmdir('test2');

unlink is for removing files.

like image 133
Petah Avatar answered Oct 06 '22 01:10

Petah