Newbie question.
Would cd "C:del *.* delete all files within the C: drive?
I was also told if I add del . /F /Q it would bypass confirmation of the deletion, but I'm not 100% sure where to put it. Do I just add it onto the end like
cd "C:del *.* del . /F /Q?
This is a dangerous command. Be careful.
No, you probably want del /F /Q ..
The first part, del, is the command. This is telling it to delete something.
/F /Q are the options, denoted by the leading slash.
/F means to force it, so for example if a file isn't writable it will still delete it if able. It also skips some other checks.
/Q tells the program to be 'quiet', so less output will be generated than normal
.(dot) is the thing to delete, which is the place you currently are. If you are currently in C:\ (ie if the terminal displays C:\> at the beginning of every line), then it will be that that it deletes.
Note that I have only shown what you should type (del /F /Q .) and not what the entire line should look like when you're done (C:\> del /F /Q .). However, if this is going in a batch file then you want the first form only.
This is a destructive command and is provided merely to answer the query - don't try it at home or prank friends with it.
This will delete all files that are not locked, or opened for exclusive access by a program.
del c:\* /s /f /q /a
It will not delete every file in a Windows system drive and will not remove directories.
Related
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.
Was writing a short script to search out all files with a certain extension, rename them and delete them... but I noticed some odd behavior in the delete script.
Let's say I have four files: file.lo, file.log, file.logs, & file.logarithm
If I use the command del /s /q /f *.lo then only file.lo is deleted. If I use the command del /s /q /f *.logs then only file.logs is deleted.
But if I use the command del /s /q /f *.log then .log, .logs, and .logarithm are deleted. The only file that remains is file.lo
Can anyone explain this behavior?
Explanation: file.logarithm matches the 8.3 short name file.log
Workaround: del file.log.
According to this answer, using an extension of exactly 3 characters in a search pattern causes the search to also return matching files with longer extensions, and otherwise allways finds exactly the right files. You should apparently use "file?.log", "file.log." as Stephan suggests, or one of these suggestions
Im not used to working in batch. I've made a database with back end and a light frontend(1mb). This front end gets updated many times so i was trying to make a batch for the users that functions as a shortcut. It should make a copy of the newest frontend save it to a subfolder and name it with the username, then open that copy.
If the user copy already exists it should just open it again.
So far i got a batch like this but it doesnt work:
if exist "H:\Database\AccountDb\%USERNAME%.accde" (
start "H:\Database\AccountDb\%USERNAME%.accde" /f /s /q
) else (
xcopy "H:\Database\frontend.accde" H:\Database\AccountDb\%USERNAME%.accde" /t /e /i /y
start "H:\Database\AccountDb\%USERNAME%.accde" /f /s /q
)
The first argument to START is treated as the window title if it is quoted. You simply need to add an empty title argument when the command must be quoted.
Also, having quotes in the middle of the path is OK, but it doesn't look particularly good. Most people put quotes around the entire path.
start "" "H:\Database\AccountDb\%USERNAME%.accde" /f /s /q
del /s .jpg
deletes all .jpgs .. but the problem is: it shows, in cmd when executed =>
C:\blabla..\this.jpg is deleted..
I want to turn this off. Such that user will not know what is happening (i.e, what files are being deleted).
Turn echo off to suppress showing the command being run, and redirect output to null as #Sico suggested.
#echo off
del /s *.jpg >nul 2>&1
You should see nothing displayed when the bat file is run.
In jammykam's answer, he uses >nul 2>&1. What this does is redirect both standard output and standard error to the null device. However, hiding the standard error is not best practise and should only be done if necessary.
#echo off
del /s *.jpg 1>nul
In this example, 1>nul only hides the standard output, but standard error will still show. If del fails to delete some files, you will be informed.
Read more about redirection
Try putting this at the top of your batch script:
#echo off
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"