We help IT Professionals succeed at work.

cmd scripting using the dir command to get desired results

franable
franable asked
on
275 Views
Last Modified: 2014-05-16
Hello,

I'm using Windows 7 as the operating system. I would like to use a standard batch script for the solution if possible, not powershell or vbs.

I'm not sure what switch to use to only get a readout of the files with the "dir" command in the directory including the size & date.

the /B following the dir command lists how I want it to look but there is no size & date following the file names. Please see the 2 examples below.

I have tried several combination of switches and I'm having problems. Can you help
Thanks

C:\Users\testuser\Desktop\testjunk>dir

 Volume in drive C has no label.
 Volume Serial Number is WXYZ-7F9B

 Directory of C:\Users\testuser\Desktop\testjunk

05/16/2014  09:08 AM    <DIR>          .
05/16/2014  09:08 AM    <DIR>          ..
05/16/2014  09:06 AM             4,848 inst1.txt
05/16/2014  09:07 AM             1,212 inst2.txt
05/16/2014  09:07 AM            25,494 inst3.txt
               3 File(s)         31,734 bytes
               2 Dir(s)   8,256,966,656 bytes free


C:\Users\testuser\Desktop\testjunk>dir /B
inst1.txt
inst2.txt
inst3.txt
Comment
Watch Question

Commented:
Try:

dir | find /V "<DIR>"

let me know...

Author

Commented:
sorry, that's not working for me, unless I'm doing something wrong

I just want the output to show the file names including the size and date

------------------
I pasted it below, what I got

C:\Users\testuser\Desktop\testjunk>dir | find /V "<DIR>"
 Volume in drive C has no label.
 Volume Serial Number is WXYZ-7F9B

 Directory of C:\Users\testuser\Desktop\testjunk

05/16/2014  09:06 AM             4,848 inst1.txt
05/16/2014  09:07 AM             1,212 inst2.txt
05/16/2014  09:07 AM            25,494 inst3.txt
05/16/2014  09:08 AM               180 New Internet Shortcut.url
05/16/2014  01:26 PM               590 New Text Document.txt
               5 File(s)         32,324 bytes
               2 Dir(s)   8,786,440,192 bytes free
CERTIFIED EXPERT
Most Valuable Expert 2019
Most Valuable Expert 2018
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Most Valuable Expert 2019
Most Valuable Expert 2018

Commented:
Short version for the command prompt to get a dir of the current directory (%~a is the file name in the loop variable, %~ta expands to the time stamp of the file in the loop variable a, %~za to the size, so you can reformat the output to your likings):
for %a in (*.*) do @echo "%~ta" "%~za" "%~a"

Open in new window

To get that recursively for subfolders as well, use "/r" after "for":
for /r %a in (*.*) do @echo "%~ta" "%~za" "%~a"

Open in new window

To use that in a batch script, double the percent signs:
for %%a in (*.*) do @echo "%%~ta" "%%~za" "%%~a"

Open in new window

The expression in parenthesis for the single directory can include a folder:
for %a in (C:\Temp\*.*) do @echo "%~ta" "%~za" "%~a"

Open in new window

For the recursive version, the folder has to be passed after /r:
for /r "C:\Temp" %a in ("*.*") do @echo "%~ta" "%~za" "%~a"

Open in new window

.
For a list of the different ways to expand a loop variable, enter "help call" in a command prompt.
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
tested both for what I need. both work well just different formatting on outputs.

and I got a couple examples I know I will also use later.

Thank you very much!!

Author

Commented:
it made me pick the best answer when assigning points, like I said they both do what I need

sorry Gastone Canali, I only picked the other answer because it was first. You answer works for me just as well

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.