Solved

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

Posted on 2010-11-23
7
1,372 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 53

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 53

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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 53

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

792 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