Avatar of franable
franable
 asked on

cmd scripting using the dir command to get desired results

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
Windows Batch

Avatar of undefined
Last Comment
franable

8/22/2022 - Mon
jjester1

Try:

dir | find /V "<DIR>"

let me know...
franable

ASKER
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
ASKER CERTIFIED SOLUTION
oBdA

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
oBdA

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.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
SOLUTION
Gastone Canali

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
franable

ASKER
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!!
franable

ASKER
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