In this case, as mentioned, we redirected the command output to a file, so we do not see any messages in the console and we just get again the prompt. So, let’s run: dir /B /A-D /O-D > listaFiles.txt We then use the redirection operator ‘ > ‘ to indicate that we want to direct the output of the command on the file “listaFiles.txt”. The files, as we can see looking at the first figure of the article, are listed by date in order from newest to oldest, so we finally got the desired result.Īt this point the last thing to do is to save this list on a new file. So, our command becames: dir /B /A-D /O-D We must therefore use the – to reverse the behavior: But by default, the D option puts the older files at the top of the list, while we need the opposite, with newest first. Returning to our example, we are required to sort the files by date, so we will use the option D. The /O option, in fact, allows us to specify a sort criteria for the items listed in the command output.Īgain, we can use the hyphen symbol – to reverse the order criteria defined by default. The solution, again, is simply between the dir command options. We are close to the solution to our request and we have just to meet the last clause, one that asks us to list the files from newest to oldest. Ok, we have succeeded and directories “Folder 1” and “Folder 2” have disappeared from the list. To do that we have to preface to the attribute the symbol – (hyphen) to indicate that we want all the files “less” those that have a certain attribute (in this case, the D directories). In this case the D attribute that indicates that the entry is a directories. But we must do exactly the opposite, so do not select items that have a given attribute, but eliminate instead those who possess it. For example, with the /AD option we can list only directories. The attributes in combination with the /A option allow us to select only the files that have certain characteristics. We must therefore find a way to indicate to the dir command that we want to exclude them.Īlso this requirement can be easily satisfied through command options in particular the /A option of the command allows us to specify the attributes that files need to have to be taken into account. However, we can notice that the result produced by the command also lists the directories and not just the file as it was required. Well, we have removed the additional information we don’t need and we now have the list of files without their full path. To do this we need to invoke the dir command with the /B option that means Bare format, ie a format that precisely not include header, size, summary, etc. First, we should eliminate all unnecessary information, such as the description of the unit type, the details about date and time related to the files and the final summary information. Looking a the output of the dir commands with no options there are several things we need to fix. Let’s start by running the dir command without any options: Starting from the content of the folder displayed above, the “listaFile.txt” file must then have the following content:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |