How to get only the number of all files on a drive? - windows

I want to get only the number of files on my hard disk drive.
I tried:
DIR /S C:\
But it lists nearly forever all the files recursively and at the end I get what I want: the number of files.
How do I get only the number of files like 300 000?

List files in bare format and pipe to find, which simply counts all lines:
dir /s /b /A-D-L c:\* | find /c /v ""
lists all files (including hidden and system files) without folders. You can adapt which files to include/exclude. See dir /? for details

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.

replace with files from multiple directories

I have a large amount of JPEG-files that have been sorted and placed in several different directories. Unfortunately these directories were lost - although I was able to restore them from an older version. However all the files are corrupted.
Luckily I still have the JPEG-files that aren't sorted and I want to replace the corrupted files with these healthy files by filename. So basically go through the unsorted files and match them with the sorted files.
I found out that by using the command replace I'm able to do this and it works perfectly with one exception: I can only go through 1 source directory at a time. This is a problem because the unsorted JPEG-files are located in ~2000 different directories.
What I'm currently doing is:
replace "folder1\folder2\folder3\folder4\*.jpg" "sorted_images_dir" /s
What I'd like to do is:
replace "folder1\*EVERY SUBDIRECTORY OF folder1*\*.jpg" "sorted_images_dir" /s
Is this possible on the commandline or would I have to create a batch file? If so, any advice for this? It seems like it would be a rather simple task.
read HELP FOR and try FOR /D %a in (*) do #echo %a this way you might iterate over all the folders in the current directory.
You might then try FOR /D /R %a in (*) do #echo %a to iterate recursively on all the folders and subfolders.
So, finally you can try
FOR /D /R %a in (*) do #replace "%a\*.jpg" "sorted_images_dir" /s

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

Command to list all files in a folder as well as sub-folders in windows

I tried searching for a command that could list all the file in a directory as well as subfolders using a command prompt command.
I have read the help for "dir" command but coudn't find what I was looking for.
Please help me what command could get this.
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.
Then in :gn, g sorts by folders and then files, and n puts those files in alphabetical order.
If you want to list folders and files like graphical directory tree, you should use tree command.
tree /f
There are various options for display format or ordering.
Check example output.
Answering late. Hope it help someone.
An addition to the answer: when you do not want to list the folders, only the files in the subfolders, use /A-D switch like this:
dir ..\myfolder /b /s /A-D /o:gn>list.txt
If you simply need to get the basic snapshot of the files + folders. Follow these baby steps:
Press Windows + R
Press Enter
Type cmd
Press Enter
Type dir -s
Press Enter
An alternative to the above commands that is a little more bulletproof.
It can list all files irrespective of permissions or path length.
robocopy "C:\YourFolderPath" "C:\NULL" /E /L /NJH /NJS /FP /NS /NC /B /XJ
I have a slight issue with the use of C:\NULL which I have written about in my blog
https://theitronin.com/bulletproofdirectorylisting/
But nevertheless it's the most robust command I know.
The below post gives the solution for your scenario.
**dir /s /b /o:gn**
/S Displays files in specified directories and all subdirectories.
/B Uses bare format (no heading information or summary).
/O List by files in sorted order.
:gn, g sorts by folders and then files, and n puts those files in alphabetical order.
Just for all files except long path, write the following command:
**dir /b /o:gn**
For Tree:
write in your cmd
tree /f

Windows CMD: List files in dir & subdir WITHOUT given extensions

I'd like to recursively search a directory and find files, which have NOT a certain extension, or precisely, which have NOT a certain set of extensions.
Sketch: find in "dir" all files without "ext1", "ext2", "ext3" and print results to .txt
I tried around several hours with DIR and ATTRIB, but unfortunately without bigger success.
Your consideration is highly regarded! Thanks.
Try this:
dir /b /s /a-d | findstr /vi ".ext1$ .ext2$ .ext3$"
The /a-d switch excludes directories, giving you only files. The findstr parameter lets you search the files for strings, and the /vi switch indicates to exclude files containing the next parameter, the search being case insensitive.
As Joey pointed out, the $ is necessary to indicate end of the line.

Resources