Solved CMD Command Prompt DIR Batch File

September 18, 2015 at 07:30:02
Specs: Windows 7 Professional
1) I use CMD to create a text file for a directory of directories (ie. 2014 Folder containing folders for each project that year).
2) Piping the DIR command to create a text file is very useful, but would love to automate the process as much as possible.
3) I import the text file into Excel to cull the data.
4) I am curious if there is a way to remove the Header and Footer (along with the folders named <.> and <..> b/c I'm not sure what they even are).
5) But would like to know if this is possible before the text file hits Excel.
6) I have come close with my current batch, but it leaves two blank rows at the top; which may not be a big deal, but I would like to know the best way possible.
*It seems this could be a very common situation, I just cannot find a specific batch w/o being to complex for my understanding.
**My current batch file uses this type of approach: DIR, REN (for whatever reason to modify the old file into a new one) and FINDSTR /V "Volume Directory .. bytes" dir01.txt.old > dir01.txt
***Please advise!

The bare format will not be useful; as I use the date created, modified, and accessed in 3 separate text files to use for tracking the projects

Would this be easier in PowerShell?

TITLE Project Folders
DIR S:\"Project Folder 2014\Projects" /T:C /O:-N > S:\MyFolder\dir01.txt
DIR S:\"Project Folder 2014\Projects" /T:W /O:-N > S:\MyFolder\dir02.txt
DIR S:\"Project Folder 2014\Projects" /T:A /O:-N > S:\MyFolder\dir03.txt
S:
CD MyFolder
REN dir01.txt dir01.txt.old
REN dir02.txt dir02.txt.old
REN dir03.txt dir03.txt.old
FINDSTR /V "Volume Directory .. bytes" dir01.txt.old > dir01.txt
FINDSTR /V "Volume Directory .. bytes" dir02.txt.old > dir02.txt
FINDSTR /V "Volume Directory .. bytes" dir03.txt.old > dir03.txt
DEL dir01.txt.old dir02.txt.old dir03.txt.old
PAUSE

message edited by mlowry54


See More: CMD Command Prompt DIR Batch File

Report •


#1
September 19, 2015 at 17:59:19
mlowry54: along with the folders named <.> and <..> b/c I'm not sure what they even are
Respectively, the directory itself, and its parent directory. Useful if you're using a CLI.

mlowry54: *It seems this could be a very common situation, I just cannot find a specific batch w/o being to complex for my understanding.
You're looking for created time, modified time, and access time. It's unusual because (a) no one cares when something was created and (b) last access time isn't used anymore. If you don't need those dates, you could use some variation of FOR.

mlowry54: Would this be easier in PowerShell?
Sure. Given Windows 7, I'd probably pick VBScript first, but PowerShell's easy enough if you manage to get scripts running.

Get-ChildItem "S:\Project Folder 2014\Projects" | 
Sort-Object -Descending Name |
Select-Object Name, LastWriteTime, LastAccessTime, CreationTime, Length | 
Export-Csv -NoTypeInformation -Force "S:\MyFolder\dir.csv"

How To Ask Questions The Smart Way

message edited by Razor2.3


Report •

#2
September 19, 2015 at 19:32:16
✔ Best Answer
Here's a vbs "front-end" to give all three timestamps for any given file (submitted via commandline):
' begin vbscript FILEDATES.VBS - using comma-sep in this case
set fso=createobject("scripting.filesystemobject")
set f=fso.getfile(wscript.arguments(0))
wscript.echo f.name&","&f.datecreated&","& f.datelastaccessed&","& f.datelastmodified
'-- end vbscript

batch interface:

for %%a in ("S:\"Project Folder 2014\Projects\*.*.) do (
cscript /nologo filedates.vbs "%%a">>allfdates*
)

::--- end batch
only marginally tested on my end. It seemed kind of slow, so for speed the DIR method might be faster if modified somewhat.

this one does it per directory instead of per file:
'begin vbscript FDATES
set fso=createobject("scripting.filesystemobject")
set f=fso.getfolder(wscript.arguments(0))
for each fil in f.files
wscript.echo fil.name&","&fil.datecreated&","& fil.datelastaccessed&","& fil.datelastmodified
next
'-- end vbscript
in this case, the argument is a directory-name and not a filename:
cscript /nologo fdates.vbs "s:\project folder 2014\projects">allfdates

message edited by nbrane


Report •

Related Solutions


Ask Question