Solved

How to Spool file names into a text file in Windows DOS based script file ?

Posted on 2010-11-23
7
1,406 Views
Last Modified: 2012-05-10

Help me in writing the DOS command to accomplish the following:

- I have a windows Folder C:\Test1
- That folder has 5 text files  (a.txt , b.txt,c.txt,d.txt,e.txt )


 File names in MS DOS


 When I do a regular DIR command it will spool all of other attributes and header part
to the spool.txt file.  But all I wanted to spool to the text file is the FILE NAMES (with extensions).

I wanted the spooled text file to show me as SPOOL.txt

1) Give me a windows batch file or any script file to accomplish this ?

2) Same script file as question (1) except that it should be able to spool file names based
    on there time stamp.  Let's say I wanted to get the text file names generated between
    4:05 PM to  4:13 PM ?
   




- Now i wanted to write a batch file or script which I would be double clicking and it should
  write a text file (Spool.txt) as follows:




 



 Output SPOOL.TXT
0
Comment
Question by:OCUBE
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 54

Expert Comment

by:Bill Prew
ID: 34201260
For part one it's a s simple as this:

@echo off
dir /a-d /b c:\test1>spool.txt

Open in new window

0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 34201280
For part 2, what date should be used in selecting the files by time?  Meaning, do you only want files from today in that time interval, or do you also want prior days files in that time window?

~bp
0
 

Author Comment

by:OCUBE
ID: 34201422


For part 2:

I need the parameters as to pass values if I need to get files from:

11/21/2010  4:10PM    
to
11/21/2010  4:50PM    


10/25/2010  4:10PM    
to
10/25/2010  6:50PM    

- I wanted to save the batch file for future reference, so just incase I have to change the dates  * time during run time.

- Can we have something where once we run the script it will ask me something like this:

Question:   What filenames you want to be spooled ?    
Answer:    *.txt

Question:   What FROM date you want to spool ?    
Answer:    11/21/2010

Question:   What TO date you want to spool ?    
Answer:    11/21/2010

Question:   What Start TIME you want to spool ?    
Answer:    04:10PM

Question:   What END TIME you want to spool ?    
Answer:    04:55PM

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 54

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 34202099
Okay, for part 2, give this VBS script a try.

You can pass the parms on the commandline like:

cscript ee26635260.vbs c:\temp pdf "01/01/2000 00:00:00" "01/01/2100 00:00:00"

or if you just run the script with no parms, it will prompt for the parms.

~bp
' Define useful constants
Const cForReading = 1
Const cForWriting = 2
Const cForAppending = 8
Const cPromptDir = "Please enter folder:"
Const cPromptExt = "Please enter file extension:"
Const cPromptFromDate = "Please enter from date/time (MM/DD/YYYY hh:mm:ss):"
Const cPromptToDate = "Please enter to date/time (MM/DD/YYYY hh:mm:ss):"
Const cSpoolFile = "spool.txt"

' See if command line contained parms, else prompt for them
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oArgs = WScript.Arguments
If oArgs.Count = 4 Then
   sBaseDir = oArgs(0)
   sBaseExt = oArgs(1)
   sFromDate = oArgs(2)
   sToDate = oArgs(3)
Else
   sBaseDir = DoPrompt(cPromptDir)
   sBaseExt = DoPrompt(cPromptExt)
   sFromDate = DoPrompt(cPromptFromDate)
   sToDate = DoPrompt(cPromptToDate)
End If

' A little cleanup on parms
sBaseExt = LCase(sBaseExt)
If Left(sBaseExt, 1) <> "." Then
   sBaseExt = "." & sBaseExt
End If
dFromDate = CDate(sFromDate)
dToDate = CDate(sToDate)

' Open output file
Set oSpool = oFSO.OpenTextFile(cSpoolFile, cForWriting, True)

' Find files in folder matching select criteria
Set oFolder = oFSO.GetFolder(sBaseDir)
For Each oFile In oFolder.Files
   sAllFiles=sAllFiles & oFile.Name & vbCRLF
   If LCase(Right(oFile.Name, Len(sBaseExt))) = sBaseExt And _
      oFile.DateLastModified >= dFromDate And _
      oFile.DateLastModified <= dToDate Then
      oSpool.WriteLine(oFile.Name)
   End If
Next

' Done
oSpool.CLose
Wscript.Quit

' User input prompt function
Function DoPrompt (sPrompt)
   ' Check if the script runs in CSCRIPT.EXE
   If UCase(Right(WScript.FullName, 12)) = "\CSCRIPT.EXE" Then
      ' If so, use StdIn and StdOut
      WScript.StdOut.Write sPrompt & " "
      DoPrompt = WScript.StdIn.ReadLine
   Else
      ' If not, use InputBox( )
      DoPrompt = InputBox(sPrompt)
   End If
End Function

Open in new window

0
 

Author Comment

by:OCUBE
ID: 34306905


Ok, I will and update
0
 
LVL 11

Expert Comment

by:paultomasi
ID: 34320460
Interesting question...

Would like to contribute to this later today...
0
 

Author Closing Comment

by:OCUBE
ID: 34475102
Thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 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