Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 666 Vote(s) - 3.47 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to delete files/subfolders in a specific directory at the command prompt in Windows

#1
Say, there is a variable called `%pathtofolder%`, as it makes it clear it is a full path of a folder.

I want to delete every single file and subfolder in this directory, but not the directory itself.

But, there might be an error like 'this file/folder is already in use'... when that happens, it should just continue and skip that file/folder.

Is there some command for this?

Reply

#2
The simplest solution I can think of is removing the whole directory with

RD /S /Q folderPath

Then creating this directory again:

MD folderPath
Reply

#3
This will remove the folders and files and leave the folder behind.


pushd "%pathtofolder%" && (rd /s /q "%pathtofolder%" 2>nul & popd)
Reply

#4
RD stands for REMOVE Directory.


/S : Delete all files and subfolders
in addition to the folder itself.
Use this to remove an entire folder tree.

/Q : Quiet - do not display YN confirmation

Example :

RD /S /Q C:/folder_path/here
Reply

#5
To delete file:

del PATH_TO_FILE

To delete folder with all files in it:

rmdir /s /q PATH_TO_FOLDER

To delete all files from specific folder (not deleting folder itself) is a little bit complicated. `del /s *.*` cannot delete folders, but removes files from all subfolder. So two commands are needed:

del /q PATH_TO_FOLDER\*.*
for /d %i in (PATH_TO_FOLDER\*.*) do @rmdir /s /q "%i"
Reply

#6
You can use this shell script to clean up the folder and files within `C:\Temp` [source][1]:

del /q "C:\Temp\*"
FOR /D %%p IN ("C:\Temp\*.*") DO rmdir "%%p" /s /q

Create a batch file (say, delete.bat) containing the above command. Go to the location where the delete.bat file is located and then run the command: delete.bat


[1]:

[To see links please register here]

Reply

#7
I use Powershell

Remove-Item c:\scripts\* -recurse

It will remove the contents of the folder, not the folder itself.
Reply

#8
[`rmdir`](

[To see links please register here]

) is my all time favorite command for the job. It works for deleting huge files and folders with subfolders. A backup is not created, so make sure that you have copied your files safely before running this command.


RMDIR "FOLDERNAME" /S /Q

This silently removes the folder and all files and subfolders.
Reply

#9


@ECHO OFF
rem next line removes all files in temp folder
DEL /A /F /Q /S "%temp%\*.*"
rem next line cleans up the folder's content
FOR /D %%p IN ("%temp%\*.*") DO RD "%%p" /S /Q
Reply

#10
CD [Your_Folder]
RMDIR /S /Q .

You'll get an error message, tells you that the RMDIR command can't access the current folder, thus it can't delete it.

**Update**:

From [this][1] useful comment (thanks to [Moritz Both][2]), you may add `&&` between, so `RMDIR` won't run if the `CD` command fails (e.g. mistyped directory name):


CD [Your_Folder] && RMDIR /S /Q .

From [Windows Command-Line Reference][3]:

> **/S:** Deletes a directory tree (the specified directory and all its
> subdirectories, including all files).
>
> **/Q:** Specifies quiet mode. Does not prompt for confirmation when
> deleting a directory tree. (Note that /q works only if /s is
> specified.)


[1]:

[To see links please register here]

[2]:

[To see links please register here]

[3]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through