Learning and Thinking Windows delete empty folders problems caused by

https://blog.csdn.net/XavierDarkness/article/details/84785482

 

 

1, a problem occurs:

  Some time ago to get a resource, claims to have nearly 500 learning materials of G, it took me so long to download down, helped myself a file search tool for re-checked, the great discovery that 500 G moisture data repetition rate very high, so of course it will re-check delete duplicate files, this has led to the existence of many empty directory under the folder, though not occupy much space, but will affect the perception index and decided to delete the empty folder.

2, problem-solving process

  Solution to the problem is the diversity of the most simple and crude is manually deleted, but 500G of data, and God knows how many empty folder, apparently not manually, after all, I am so lazy. This time we should ask whether there are ways to web search engines lazy. He said online software to clean up, emmm ... a little heart, but does not occupy much space for a number of empty directories go next few M software, a bit uncomfortable. Thus, another method decided, the command line.

  Most of the Internet gives the command batch bat to delete empty folders. We simply resolve it:

OFF @echo
for / F "delims =" %% A in ( 'the dir / B / AD / S ^ |. Sort / R & lt') do RD / Q "%% A" 2> NUL
. 1
2
@echo OFF not to say a close echo
for command, read loop operation is performed following figure gives a brief introduction, details can be found for /?

dir. / b / ad / s , with an empty format (/ b) display the specified directory (the current directory (.)) file (directory and all subdirectories (/ s) of the file attributes (/ a) is also a directory a special kind of file). It simply is recursively list all directories. Further details dir /?
The Sort / r reverse order. | Pipeline breaks, the | input commands after the command output as before. Here is the effect in reverse order, so that subdirectory will be arranged in the front.
for / f "delims =" %% a in ( 'dir / b / ad / s ^ |. sort / r') do pass the result for the cycle, the latter do commands sequentially executed. "delims =" is used to specify the delimiter. Since () command is nested, so use single quotes ''. '. dir / b / ad / s ^ | sort / r' where ^ is the escape character.
rd / q ".rd command default is to delete the empty folder, / q quiet mode, do not require confirmation. For details, see RD / ?.
2> NUL, could not find information in this regard, suggesting that should the Linux 2> / dev / null cognate .2 represents the error output of the reference article. "2> / dev / null and> / dev / null 2> & 1 and 2> & 1> / dev / null - in Qi 2513 ape green - CSDN blog"
for / F "delims =" %% a in ( '. dir / b / ad / s ^ | sort / r') do rd / q "%% a" 2> nul Overall, one by one is to use a for loop to delete () command generates a list of directories empty directory, and no echo error message.
  It should be written in great detail of it. Batch command has the advantage that you can write once use many times. This batch is to start looking from the current directory, so each time you use this bat just need to move the file to the root directory of the file you want to delete an empty directory folder (note, not a disk root directory).

Batch commands and command line or less, and finally write the command line:

for / f "delims ="% a in ( 'dir [ you want directory] / S / B / AD ^ | Sort / R & lt') A 2% do RD> NUL
. 1
  When you run a command, it is not found nothing happens, do not panic, it's just reading the file list (execution dir), you may file a bit more, you can take two steps, first with dir, the file directory listing writes a txt file, then for read the file.

PS: In the bat file before for command, you can add color 0A command, so that your output will be green on a black background, if you file more, then there will be a feeling of geeks, are interested and seeking.

If wrong, please correct me. (〃 '▽' 〃)

Guess you like

Origin www.cnblogs.com/onelikeone/p/11965846.html