Deleting folders present on remote machine using batch file
19,501
Solution 1
A less comprehensive, but more simple answer...
del /F \\myserver\w_root$\users\selah\selah.txt
del /F \\myserver\w_root$\users\selah\status.txt
Solution 2
As long as you can mount the remote folder with a user who has delete authority, you can simply do something like this:
rem Set up the remote path - assuming it is sharable
set MY_DIR=\\10.1.1.1\some\path
rem Mount the remote path
net use %MY_DIR% %MY_PASSWORD% /USER:%MY_USER%
rem Delete a file
if exist "%MY_DIR%\MyFile" del /F "%MY_DIR%\MyFile" >nul
rem Unmount the remote path
net use %MY_DIR% /delete >nul
If you want to remove folders, you'll just need to make sure the mount point is at least one level above where you'll be deleting.
Related videos on Youtube
Author by
Sachin Mhetre
It is better to conquer yourself than to win a thousand battles. Then the victory is yours. It cannot be taken from you, not by angels or by demons, heaven or hell.
Updated on September 15, 2022Comments
-
Sachin Mhetre over 1 year
I want to delete couple of folders using batch file.
But problem is that these folders are present on some other machine.
But I can take the remote access to this machine on my machine.Please help me with this issue. I don't have any idea about this.