Solved

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

Posted on 2010-11-23
7
1,338 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 52

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 52

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 52

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

920 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