Reputation: 453
I am new to the command prompt want to know how all the command works …
I want to know how to apply pipe and filter in cmd
to go through the directory and print only those files/folders that were created on a particular date, and want to use a data that occurs 2 -3 times within the files and folders of your test directory.
Upvotes: 23
Views: 77306
Reputation: 5954
To use regular expressions, these two examples for tem
and me
may help.
Given these folders inside C:\tmp\Regex_Test
C:\tmp\Regex_Test>tree
C:.
├───atem
├───atem1
├───tem
├───temA
└───xtemB
List the content of the directory C:\tmp\Regex_Test
and filter for every entry that has tem
somewhere.
C:\tmp\Regex_Test>dir | findstr /R tem
20.03.2024 10:37 <DIR> atem
20.03.2024 10:37 <DIR> atem1
20.03.2024 10:36 <DIR> tem
20.03.2024 10:36 <DIR> temA
20.03.2024 10:36 <DIR> xtemB
Another example, list all entries that contain me
and does have at least one character in front and at the end. This will not find a folder named me
C:\Windows>dir | findstr /R .me.
Volume in Laufwerk C: hat keine Bezeichnung.
Volumeseriennummer: 861F-B705
07.12.2019 11:14 <DIR> GameBarPresenceWriter
16.06.2023 23:37 <DIR> ImmersiveControlPanel
01.10.2023 14:19 <DIR> SensorFramework
Upvotes: 1
Reputation: 5615
<your_command> | findstr "search_string*"
you can use parameter like /I
/B
etc. you can also use Regular expression for more information about findstr
please see the reference help findstr
Upvotes: 23
Reputation: 80213
Go to Start>Help and support enter command prompt
in the box and press the magnifying glass symbol at the end. Then select Command Reference Overview [H1S]
from the list displayed. This will show the commands available.
Obviously, there are other articles that may be of aid as other selections.
Generally, typing
commandname /?
from the prompt will show (often cryptic) help
|
is used to direct the output of one command to the input of a second, so
dir | sort
for instance takes the screen-output of the DIR
command and SORT
s it.
The next question uses the critical term created
. Each file may have THREE different times, the time the file was created
, the time the file was last written
to and the time the file was last accessed
. It's possible to access all three times, but the default is the time last written
. This is the normal time reported by DIR, and can variously be referred to as the file time
or the update time
amongst other terms.
Hence, to list the files (using the common written
date) and select on a particular date, try
dir | find "dateyourequire"
where you need to replace dateyourequire
with the target date, in the format matching that displayed by your DIR
command. BTW commands are NOT case-sensitive - with one important exception.
Now date-format is a whole new ballgame, and you need to be very careful because the date shown is according to local convention. Some people use DD/MM/YY
for instance - others use MM-DD-YY
and there are many others. If you are discussing date and time, you need to say EVERY TIME the convention you are using.
data that occurs 2 -3 times
point. I can make neither head nor tail of it. Examples are usually a good way.
Upvotes: 26