I need some help with a batch program to delete Minecraft on start up, because my friend likes to prank me with downloading Minecraft to my computer when I am away. Anyways, here is the code.
#echo off
cd/
CLS
rmdir /S /Q C:\Users\William\Downloads\Minecraft.exe
rmdir /S /Q C:\Users\William\Desktop\Minecraft.exe
rmdir /S /Q C:\Users\William\Appdata\Roaming\.Minecraft
MOVE "C:\Users\William\This pc\Documents\Minecraftdel.bat" "C:\Users\William\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
pause
I get the errors:
The directory names is invalid. The system can not find the specified file.
The system can not find the specified file. The syntax of the command is incorrect.
The errors are in the order of the commands!
I have checked that the files are there and I did copy the path from the File Explorer.
You are trying to use rmdir to delete a file. Use the DEL command instead.
DEL C:\Users\William\Downloads\Minecraft.exe
DEL C:\Users\William\Desktop\Minecraft.exe
Related
Can I delete a file that is the one running the batch that is deleting the file?
I need to make a batch file that will run if the username for the program isn't right. It's like recaptcha but more annoying, when it is run it deletes all the files in the same folder then self destructs.
To clarify, you are looking to remove the batch file after completion.
I think this StackOverflow post can help you.
EDIT
I don't know too much about Batch but a quick search gave me this:
#Echo off
set folder="C:\test"
cd /d %folder%
for /F "delims=" %%i in ('dir /b') do (rmdir "%%i" /s/q || del "%%i" /s/q)
del "%~f0"
This would delete all files and folders inside the folder variable you specify.
Then you can append to this script with one of the answers from the StackOverflow post I mentioned at the start. I picked one at random, hence the del "%~f0"
It is pretty damn simple. Just write this into the batch and place it in the directory.
del /Q /F *
Which will delete everything in the folder, including the batch file itself.
Note!! I take no responsibility if you delete something you were not supposed to.
This is all you need at end of file
rmdir "C:\directory" /S /Q
del "C:\my.bat"
Make sure the program and the directory you are deleting are different. I personally have file in the startup to delete my program once set to self-destruct on restart
I've been working on a code to delete the files from a Location inputted in .txt file.
#echo off
cd C:\Users\Troy\Desktop\Details
set /p loc=<Location.txt
rd /s /q "%loc%"
echo %loc%
pause
This code returns me the following output
The directory is not empty.
C:\Users\Troy\Downloads\TV Shows
Press any key to continue ...
Now the file Location.txt, when opened contains following
C:\Users\Troy\Downloads\TV Shows which is in accordance with the echo output I get in the second line (of the above output)
Also note that I have saved the batch file at C:\Users\Troy\Desktop
So there arises no reason for any interference due to the same location.
The weird part is when I run the following code from another batch file at the same location it runs perfectly fine and deletes all the files.
#echo off
set loc=C:\Users\Troy\Downloads\TV Shows
rd /s /q "%loc%"
echo %loc%
pause
So the only difference between the two codes is that the first one sets the variable location from a specific file, whereas the other one has a pre- inputted variable.
Also I have tried to delete files from the location using the following code
#echo off
cd C:\Users\Troy\Desktop\Details
set /p loc=<Location.txt
cd %loc%
del /s /q * >nul 2>&1
cd C:\Users\Troy\Desktop\Details
rd /s /q "%loc%"
echo %loc%
pause
In the above code, the delete command works perfectly fine and deletes all the files within. However folders and subfolders are all that are left, which means that rd command is not working
I've even tried the attrib -h thing, but that does not work either.
Also note that I've tried this with various permutations and combinations of rmdir /s /q too. But does not work.
Any help appreciated.
You could be suffering from some corruption in the file system. Try running chkdsk /f. You'll have to reboot in order to run it, but see if it finds something that it can correct, then see if your problem goes away.
So short from writing out every possible file path. Is there a way to delete a specific exe file that could be anywhere on the computer?
C:
del C:\Users\Student\Downloads\blah.exe
del C:\Users\Student\Documents\blah.exe
del C:\Users\Student\music\blah.exe
Open a command prompt window and execute there del /?
You get displayed the help for command del listing also parameter /S for deleting all files matching the file name or file name pattern in all subdirectories.
For example blah.exe is deleted in all subdirectories on drive C: with following command:
del /F /Q /S C:\blah.exe
Excepted are all directories with no permissions for deletion of a file for the current user executing this command.
Perhaps better for your example would be
del /F /Q /S "%USERPROFILE%\blah.exe"
I have a follow bat command which will delete unnecessary files when i give respective file extension
#ECHO OFF
REM Change the path and the extension...
DEL /s /f /q "C:\Users\dell\Desktop\test\*.pdf"
DEL /s /f /q "C:\Users\dell\Desktop\test\*.csv"
ECHO Are you sure ? Press a key to continue.
PAUSE > NUL
ECHO Done
PAUSE
I am in need to insert specific sub-folder to delete along with files. Assume specific sub-folder name may be abc
Can any body help me on this how to insert "delete specific sub-folder"
Use the RD command to remove a (sub)directory. Since a directory may not be empty, you may want to add the /S switch to remove the entire directory tree. And since you are also going to use the command in a batch script, you may need the /Q switch as well, to avoid the confirmation prompt.
So add a command like this to your script:
RD /S /Q "C:\Users\dell\Desktop\test\Specific\Subfolder"
I try in my batch file o delete folder(BR) with many files and subdirectories, I try the following:
if exist C:\BR (
rmdir "C:\BR" /S /q
)
but sometimes I get an error that a specific folder is not empty.these folder contains files of CSS.
what the problem??
rd /s /q DIRNAME
rmdir /s /q DIRNAME
The files that you can't delete are in use.
Close whatever program is holding them open, probably your browser, and try again.
Let me guess, your trying to delete your %TMP% folder.
EDIT: To answer zipi's question.
It will delete every file and folder that it can. So, if c:\tmp\dir2\dir3\open.txt is open, c:\tmp\emptyDir is an empty directory, and you do this:
c:\>dir c:\tmp /b /s
c:\tmp\a.txt
c:\tmp\dir2\b.txt
c:\tmp\dir2\dir3\open.txt
c:\>rd /q /s c:\tmp
c:\>dir /s /b c:\tmp
c:\tmp\dir2\dir3\open.txt
You will have deleted:
c:\tmp\a.txt
c:\tmp\dir2\b.txt
And removed:
c:\tmp\emptyDir
But still have the directories...
c:\tmp
c:\tmp\dir2
c:\tmp\dir2\dir3
...an the file:
c:\tmp\dir2\dir3\open.txt
If instead, a.txt was open, you'd only have:
c:\tmp\
and
c:\tmp\a.txt
On win7 I use a simple bat file to go around the problem:
call :rmdir "my_directory_01"
call :rmdir "my_directory_02"
pause
goto :EOF
:rmdir
if exist %1 rmdir /s /q %1
if exist %1 goto :rmdir
goto :EOF
I had a similar problem. Tried lots of different solutions, but ultimately only the following worked:
rmdir c:\<directory> /s /q
Previously using other methods in CMD I was getting the following:
The directory is not empty.
I had the same issue and the solution is very silly. Please use /Q first and the /S to resolve your issue. so command should be something like:
IF EXIST %build_folder% RD /Q /S %build_folder%
Please let me know if this solves your issue.
Regards
Anuj
To remove directory in command line, you have to remove all of files and subsolders it cointainst at the first place. The problem may occur if some of those items are read-only. /f will try to force delete them.
Try
if exists C:\BR (del "C:\BR" /f /s /q)
Here you have MS docs of the DEL command: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/del.mspx?mfr=true
This worked for me
you will need to go to any drive where the folder is. Then right click on drive > properties > Check Scan disk or scan drive and for windows8 scan and repair
then go back to your folder and delete it
Batch - Getting "The directory is not empty" on rmdir command
In my case the failure to remove a directory using rd /Q /S and getting Directory not empty was down to file permissions. The batch job was doing a backup and removing oldest backup folder at the end to keep latest 10 backups. The normal user account only had read and execute permission on certain files in the sub folders. Running the batch file containing the rd commands under Task Scheduler with a tick in the option "run with highest privileges" enabled directory's to be removed.
You could achieve something similar as a one off if you run your batch file under cmd and choose run as administrator. In Windows 7 type CMD in the Search programs and files box, then right click on cmd.exe at the top of the popup window and click Run as Administrator. Then find and run your batch file in the cmd "black background" window.