[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

simple dos command to find number of files in a directory or folder

Posted on 2011-05-01
10
Medium Priority
?
1,055 Views
Last Modified: 2012-05-11
I need to find a simple command (from dos) to find out number of files in a given directory (or path).

currently, it will display all the filename first, then at the end, it give me number of files.

thank you
0
Comment
Question by:mshox1
  • 3
  • 3
  • 2
  • +1
10 Comments
 
LVL 3

Accepted Solution

by:
OrenRozen earned 800 total points
ID: 35500223
the following command will return the total number of file in the current folder.

for /f "tokens=1" %a in ('dir ^| find /i "File(s)"') do @echo %a Files

you can add after the DIR command any path you want.
0
 
LVL 3

Assisted Solution

by:OrenRozen
OrenRozen earned 800 total points
ID: 35500244
another option, save the following script in your system32 folder with the name tfiles.cmd.

now, when you type the command tfiles d:\ from any location you'll get the result for total number of files in d:\.

tfiles with no arguments will return the number of files in the current folder.
 
@echo off

for /f "tokens=1" %%a in ('dir %1 ^| find /i "File(s)"') do @echo %%a Files

Open in new window

0
 
LVL 71

Assisted Solution

by:Qlemo
Qlemo earned 800 total points
ID: 35500306
If the number of bytes does not disturb, simply filtering the output will suffice:
   dir c:\somepath | find "File(s)"
For having a (simple) listing including subfolders
   dir c:\somepath /s | findstr /L "Directory File(s)"

For pretty-printing the second one we need more effort, but it is not difficult.
0
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 
LVL 59

Assisted Solution

by:Bill Prew
Bill Prew earned 400 total points
ID: 35500356
Here's one of the simplest ways I know.

dir /a /b | find /v /c ""

Open in new window

~bp
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 35500358
Sorry, cut and paste error, should be:

dir /a-d /b | find /v /c ""

Open in new window

~bp
0
 

Author Comment

by:mshox1
ID: 35500438
what is the above command will do?  
      

dir /a-d /b | find /v /c ""

Like to know more explanation of this command's variables.

thanks

0
 
LVL 71

Assisted Solution

by:Qlemo
Qlemo earned 800 total points
ID: 35500448
dir /a:-d   (or /a-d)   will suppress all directories
dir /b   only shows file names (prefixed with paths, if /s for "list subfolders" is used in addition).
Both together display all file names, no size or dates.

The find /v /c "" is a tricky command to just count all lines, and output only that count.
0
 

Author Comment

by:mshox1
ID: 35500470
thank you.

I have a follow up questions:

what is the best and simple command to copy all the files/subfolder  from 1 place to the others?

xcopy c:\base_folder /s    y:\base_folder   /y /v

-- I like to copy a folder, with all its files and sub directory, to another driver,  replace the file is exist,
  if folder not exist, will create it,  if folder exist, will replace it,  and then verify if copy complete.

thanks

0
 
LVL 71

Expert Comment

by:Qlemo
ID: 35500480
Sorry, but that is no follow up question, because it isn't related. EE protocol says you need to post a new question for that.
0
 

Author Closing Comment

by:mshox1
ID: 35500495
thanks a lot
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A safe way to clean winsxs folder from your windows server 2008 R2 editions
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
This tutorial will give a an overview on how to deploy remote agents in Backup Exec 2012 to new servers. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as connecting to a remote Back…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
Suggested Courses

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question