Link to home
Create AccountLog in
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
Avatar of jjester1
jjester1

Try:

dir | find /V "<DIR>"

let me know...
Avatar of 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
Avatar of oBdA
oBdA

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
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.
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
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!!
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