windows cmd: searching files with specific path - windows

Maybe trivial question but certainly hope someone can help me here..
Windows cmd:
I want to search for files in a root directory and its subdirectories where the files have a parent directory with a specific name. (in this example: \TO). This parent directory has always the same name but can be another directory (if the path is different)
I tried this but doesn't seem to work: dir \root /b /s *\TO *.java
I also tried to pipe the output of dir to find.. But cannot make 'find' to show the lines containing the desired paths..

From the cmd prompt:
for /r \ %a in (to\*.java) do #echo %a

Related

Windows CMD to list all files from multiple directories path

I need command line to list all files inside folder from many directories like :
C:\Program Files\folder1
D:\Data\folder2
I want to do it with single command line, is there a way to do it?
Thanks for the help
The below post gives the solution for your scenario.
dir /s /b /o:gn
/S Displays files in specified directory and all subdirectories.
/B Uses bare format (no heading information or summary).
/O List by files in sorted order.
Thanks to this post.

Get a list of files present in a folder

I want the names of the files present in a folder . Is there any command in command prompt or any other way that can list all the file name(only file name and its extension) that are present in a particular folder?
Dir does what you want, you may want to add /B to only get filename and extension.
dir /B
Full options of dir can be viewed by
dir /?
Try dir /B that should give you the expected result.

verifying whether file exists or not in a specified drive and its subfolders?

I am using windows OS. I am trying to find out whether a specific file exists or not in a directory. currently i am using below command.
d:\> c:\Desktop\some.exe
but the problem is above command does not verify in sub folders of d drive. how can i write the command to look even in subfolders?
Thanks!
You can get a list of all files in subdirectories with this command
dir "yourfilename.ext" /s /b
If you want to know is how many times your file "yourfilename.ext" is present then you could extend the previous command with
dir "yourfilename.ext" /s /b | find /C "yourfilename.ext"

How to do a simple file search in cmd

I want to quickly search for a file given its name or part of its name, from the windows command line (not power shell). This is similar to opening explorer and using the search box at the top.
Note: dir can search based on a string template but it will not search in the subdirectories.
Note2: findstr can be used to search for a token inside files and has a recursivity flag; it's funny that a more complex find can be easily discovered ...
dir /s *foo* searches in current folder and sub folders.
It finds directories as well as files.
where /s means(documentation):
/s Lists every occurrence of the specified file name within the
specified directory and all subdirectories.
dir /b/s *.txt
searches for all txt file in the directory tree. Before using it just change the directory to root using
cd/
you can also export the list to a text file using
dir /b/s *.exe >> filelist.txt
and search within using
type filelist.txt | find /n "filename"
EDIT 1:
Although this dir command works since the old dos days but Win7 added something new called Where
where /r c:\Windows *.exe *.dll
will search for exe & dll in the drive c:\Windows as suggested by #SPottuit you can also copy the output to the clipboard with
where /r c:\Windows *.exe |clip
just wait for the prompt to return and don't copy anything until then.
EDIT 2:
If you are searching recursively and the output is big you can always use more to enable paging, it will show -- More -- at the bottom and will scroll to the next page once you press SPACE or moves line by line on pressing ENTER
where /r c:\Windows *.exe |more
For more help try
where/?
dir *.txt /s /p
will give more detailed information.
Problem with DIR is that it will return wrong answers.
If you are looking for DOC in a folder by using DIR *.DOC it will also give you the DOCX. Searching for *.HTM will also give the HTML and so on...
You can search in windows by DOS and explorer GUI.
DOS:
1) DIR
2) ICACLS (searches for files and folders to set ACL on them)
3) cacls ..................................................
2) example
icacls c:*ntoskrnl*.* /grant system:(f) /c /t ,then use PMON from sysinternals
to monitor what folders are denied accesss.
The result contains
access path contains your drive
process name is explorer.exe
those were filters youu must apply

How to search a hard drive for a directory name using DOS

Is there a way to find a file on the C: of a computer , using a DOS command, without having to CD to the root of the C: drive? I would like to do it using the DIR and the FINDSTR command only.
Ultimately, my goal is to search for a file and then store the parent directory name in a ENV variable without changing directories and hopefully without creating a temp file.
Have a look at How to find a file in MS-DOS.
dir *bob*.* /s
See also List of DOS commands
This gets the complete file name with directory in a useable form.
dir C:\FILENAME.EXT /s /b
c:> findstr /s /i *.ext
REM finds in drive c: every file called *.ext containing (case insensitive)

Resources