CMD dir command - windows

I'm using dir to retrive all directories from specified path but I'm getting directories paths from two locations.
dir "C:\ssis" /b /s /ad *.* | sort >c:\ssis\task4\content.txt
And result is
I want to get only marked (yellow) lines. Not directories from place where I open CMD
Thanks :)
PM

remove *.*:
dir "C:\ssis" /b /s /ad | sort >c:\ssis\task4\content.txt
Because you specify the directory where you want to list the files earlier "C:\ssis" so *.* will also list files in actual directory.

Related

Windows cmd: piping the dir list output into find (or findstr) is not working

I need to do some very big Windows searches for some specific searchterms in th contents of all the files in a folder and all sub-folders. The GUI search facility is not finding all my tests, so I would like to try to use find via the cmd.
I can list all filenames in raw data format using:-
dir /S /B
I can successfully search for the searchterm in thecontents of all files in a single folder using :-
find "Searchterm" *.*
But there are thousands of recursive sub-folders, so when I pipe the output from the dir listing to the find (and exclude the filename parameter):
dir /S /B | find "Searchterm"
I am getting no results.
Furthermore, I have also successfully sent all the dir /B /S filenames to a text file:-
dir /S /B >> filenames.txt
and using type to pipe the contents of each file from the list to the find :-
type filenames.txt | find "Searchstring"
This does not work either. What am I missing? Microsoft's documentation suggests exactly the same format in https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/find as I am trying.
The solution to your question(s) should be clear by reading the output from %SystemRoot%\System32\findstr.exe /? ENTERed in a Command Prompt window.
I'd advise that you use the /L, literal, option for your initial code.
Direct results example:
%SystemRoot%\System32\findstr.exe /I /L /P /S "Searchstring" *
If you first send the filenames to a text file, e.g. Dir /B /S /A:-D 2>NUL 1>"filenames.txt", you could use the following idea:
%SystemRoot%\System32\findstr.exe /F:"filenames.txt" /I /L /P "Searchstring"
Just be aware, in this case, that unless you include a path outside of the target tree when initially creating filenames.txt, it will include itself in its own content. That means your FindStr command will also pick up any matches in that file too.

List files in subdirectories but don't list directories

When I do a dir /s /b command from command prompt I get the ususal files in the directory,subdirectories,and files in the subdirectories.For example:
C:\Files\more_files>dir /b /s
C:\Files\more_files\18.0.1025.39 Dev_chrome_installer.exe
C:\Files\more_files\7z920.exe
C:\Files\more_files\Firefox Setup 2.0.exe
C:\Files\more_files\ie6setup.exe
C:\Files\more_files\qbasic
C:\Files\more_files\sp6i386.exe
C:\Files\more_files\Thunderbird Setup 10.0.1.exe
C:\Files\more_files\qbasic\QBASIC.EXE
C:\Files\more_files\qbasic\QBASIC.HLP
C:\Files\more_files\qbasic\QBASIC.INI
C:\Files\more_files>
But I dont want subdirectories listed,but I want the files in the subdirectories listed.Basically, I want dir to not show subdirectories, but show the files in them.Here is an example with subdirectories removed:
C:\Files\more_files>dir /b /s
C:\Files\more_files\18.0.1025.39 Dev_chrome_installer.exe
C:\Files\more_files\7z920.exe
C:\Files\more_files\Firefox Setup 2.0.exe
C:\Files\more_files\ie6setup.exe
C:\Files\more_files\sp6i386.exe
C:\Files\more_files\Thunderbird Setup 10.0.1.exe
C:\Files\more_files\qbasic\QBASIC.EXE
C:\Files\more_files\qbasic\QBASIC.HLP
C:\Files\more_files\qbasic\QBASIC.INI
C:\Files\more_files>
I removed the qbasic subdirectory from the listing, but it still shows the files in the subdirectory(s).I want to use this for a cahce manifest for a webapp but with a different folder.Also, is there a way to list files in subdirectories but not the subdirectories themselves in Linux using ls?
Try:
dir /b /s /a-d
/a-d means "A" attribute, "-" no , "d" directories

Running dir against multiple directories

If I run, for example:
dir /s /b /o:gn "c:\Program Files\TrueCrypt" | findstr .sys
I comfortably get
c:\Program Files\TrueCrypt\truecrypt.sys
c:\Program Files\TrueCrypt\truecrypt-x64.sys
..in return. But if I add a folder that doesn't exist (I won't go into the reasons why this would be the case, but it will be), I just get an error:
dir /s /b /o:gn "c:\Program Files\TrueCrypt" "c:\non folder\non subfolder" | findstr .sys
The system cannot find the file specified.
Unlike in the UNIX world where I can use "find" and it returns files found in any directories without only barfing on the directories that don't exist.
You can use a loop and call dir for each of the folders:
for %F in ("c:\Program Files\TrueCrypt" "c:\non folder\non subfolder") do (
dir /s /b /o:gn "%F"
) | findstr .sys
However, depending on what you need exactly you can probably do better by ditching dir and findstr here and opt for a loop over the files. But that depends a bit on what your overall goal is.

dir command not current directory and filter

I am trying to list all the files with a specific extension but not the current directory.
Something like this
dir "C:\x y\test\" /b /s *.txt
but instead of the expected result it lists all the files from the specified directory AND the ones from the current directory.
Is there a way to get list the files with a specific extension from another directory than the current one
I'm not really sure, but i think it would be
dir "C:\some\path\*.txt" /b /s /a-d
Do you look for something like
dir "c:\temp\*.txt"
As a fact I am not in c:\temp.
How about FORFILES? It's more robust than the old "dir":
FORFILES /P "Your/Path" /S /M *.txt
*/p = The Path to search
*/s = Recurse into sub-folders

Windows: How to list all the files in directory and sub directory with full path and creation date

I am using the below command but its giving only the full path of the files and not the creation date.
Is there any way I can get the full path with creation date also.
dir /s /b
Try this:
dir /s /T:C
I got it using dir /?

Resources