Solved

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

Posted on 2010-11-23
7
1,358 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
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 Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

813 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

18 Experts available now in Live!

Get 1:1 Help Now