Solved

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

Posted on 2010-11-23
7
1,328 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
  • 3
  • 3
7 Comments
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
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 51

Expert Comment

by:Bill Prew
Comment Utility
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
Comment Utility


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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 51

Accepted Solution

by:
Bill Prew earned 500 total points
Comment Utility
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
Comment Utility


Ok, I will and update
0
 
LVL 11

Expert Comment

by:paultomasi
Comment Utility
Interesting question...

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

Author Closing Comment

by:OCUBE
Comment Utility
Thanks
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now