Reputation: 625
I am very new to writing windows batch programmes.
I am trying to delete a pdf file in my batch programme. However the file is not getting deleted. I don't know what is wrong with this code. It works well when i try to delete a .txt file. I don't know how to trap the error also. It will be really helpful if you can guide me or redirect me to an appropriate forum.
This is the code I use:
echo Y | del \\file_path\filename.pdf
Upvotes: 0
Views: 55
Reputation: 947
Try to do it with powershell, if you get "access dined" just run your PS console as administrator. Here is the simple code:
$myfile = "C:\Myfile.pdf"
Get-Item -Path $myfile | Remove-Item -Force
Update:
You can also use this script to remove your file from a share:
$myfile = "\\server\share\myfile.pdf"
Get-Item -Path $myfile | Remove-Item -Force
You can also run this script from a batch file:
Save the script above somewhere on your local disk eg "c:\myscript.ps1"
Create a new batch file with this command:
powershell.exe -Executionpolicy remotesigned -File c:\myscript.ps1
Where "c:\myscript.ps1" is the path to your powershell scipt
Upvotes: 1