How to write a DOS program to search the disk.

A

Academia

Thanks for this.
I'll try it now


Pegasus (MVP) said:
As it happens, some issue arose in a completely different context.
A spin-off from that problem is the script below. It will create a
list of files that have been accessed during the last 30 days, which
is probably what you wanted. Here is how to implement it:

1. Create a file c:\windows\MyDecompress.bat and put the
following lines inside:
@echo off
cscript //nologo c:\windows\MyDecompress.vbs c:\windows\xxx.bat
rem call c:\windows\xxx.bat

2. Create a file c:\windows\MyDecompress.vbs. Paste the code
below into it.

3. Adjust Lines 1, 2 and 3 to suit your environment.

4. Unwrap any wrapped lines in that code, then remove all the
line numbers.

5. Save & close the file.

6. Run c:\windows\MyDecompress.bat.

7. Examine the file c:\windows\xxx.bat.

8. If you're satisfied with the result, edit the file
c:\windows\MyDecompress.bat
and remove the word "rem" from Line 3. This will activate the batch
file.

That's it!

1. Const Age = 30 'Age cut-off
2. Const Source = "C:\Windows"
3. const command = """c:\tools\decompress.exe"""
4.
5. Set objArgs = WScript.Arguments
6. if objArgs.Count = 0 then
7. wscript.echo "Missing output file name"
8. wscript.quit
9. end if
10.
11. Set ObjWshShell = WScript.CreateObject("WScript.Shell")
12. Set ObjExec = ObjWshShell.exec("%ComSpec% /c dir /a-d /s /ta " &
Source)
13. Set fso = CreateObject("Scripting.FileSystemObject")
14. Set OutputStream = fso.CreateTextFile(objArgs(0))
15. WScript.Echo "Processing files . . ."
16.
17. Do
18. line = ObjExec.StdOut.ReadLine
19. If InStr(line, " Directory of ") = 1 then dir = Mid(line, 15) & "\"
20. if instr(line, "/") > 0 then Call ProcessLine()
21. Loop Until ObjExec.StdOut.AtEndOfStream
22.
23. OutputStream.close
24.
25. '-------------------
26. 'Process one line
27. '-------------------
28. Function ProcessLine()
29. D = CDate(Mid(line, 5, 10) & Mid(line, 16, 6))
30. If DateDiff ("d", D, Now) < Age Then
31. OutputStream.WriteLine command & " """ & dir & Mid(line, 41) & """"
32. End If
33. End Function
34.
35. '---------------------------------
36. 'Pad single digit numbers with a 0
37. '---------------------------------
38. Function Pad (N)
39. If N < 10 Then
40. Pad = "0" & N
41. Else
42. Pad = N
43. End If
44. End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top