How to write a DOS program to search the disk.

A

Academia

Thanks to John John I know about
compact /u /i /a /s:<filename>


What I would like to do is decompress all files that have been accessed in
the last 30 days.

I used to write in a no longer used script and what I would do then is write
and run a script that would search the disk and build a .bat file, each line
of which would decompress one file. Then run the .bat file over night.

I have no idea if that is a reasonable thing to do in DOS.

If it is can you point me to an example or show me how do that?

The example wouldn't have to relate to compact but it would be nice if it
showed how to build such a file.

Or maybe you have a better approach.


Thanks in advance for any helpful suggestions
 
P

Pegasus \(MVP\)

Academia said:
Thanks to John John I know about
compact /u /i /a /s:<filename>


What I would like to do is decompress all files that have been accessed in
the last 30 days.

I used to write in a no longer used script and what I would do then is
write and run a script that would search the disk and build a .bat file,
each line of which would decompress one file. Then run the .bat file over
night.

I have no idea if that is a reasonable thing to do in DOS.

If it is can you point me to an example or show me how do that?

The example wouldn't have to relate to compact but it would be nice if it
showed how to build such a file.

Or maybe you have a better approach.


Thanks in advance for any helpful suggestions

You could use this batch file:
#@echo off
#set Source=D:\My Files
#echo WScript.Echo Month(Date-30) ^& "/" ^& Day(Date-30) ^& "/" ^&
Year(Date-30)> "%temp%\MyDate.vbs"
#for /F %%a in ('cscript //nologo "%temp%\MyDate.vbs"') do set MyDate=%%a
#
#echo Decompressing all files modified since %MyDate%
#for /F "delims=" %%a in ('xcopy /s /L /d:%MyDate% "%Source%\*.*" c:\ ^|
find ":"') do (
# echo Decompressing "%%a"
#)

Please note:
- Do not retype this file - use copy & paste instead.
- The # characters are there to mark the beginning of each line.
You must remove them before running the batch file.
- Test the file as it is - it won't do anything good or bad.
- After testing the file, add your decompress command right
after the line that says
echo Decompressing "%%a".

Post again if you need an explanation about this code.
 
A

Academia

Pegasus (MVP) said:
You could use this batch file:
#@echo off
#set Source=D:\My Files
#echo WScript.Echo Month(Date-30) ^& "/" ^& Day(Date-30) ^& "/" ^&
Year(Date-30)> "%temp%\MyDate.vbs"
#for /F %%a in ('cscript //nologo "%temp%\MyDate.vbs"') do set MyDate=%%a
#
#echo Decompressing all files modified since %MyDate%
#for /F "delims=" %%a in ('xcopy /s /L /d:%MyDate% "%Source%\*.*" c:\ ^|
find ":"') do (
# echo Decompressing "%%a"
#)

Please note:
- Do not retype this file - use copy & paste instead.
- The # characters are there to mark the beginning of each line.
You must remove them before running the batch file.
- Test the file as it is - it won't do anything good or bad.
- After testing the file, add your decompress command right
after the line that says
echo Decompressing "%%a".

Post again if you need an explanation about this code.

Did you just write this?
If so that is IMPRESSIVE!

I guess you wanted me to cut and paste because DOS is very particular, so
I'm bringing to your attention the way the "for" line is separated.

Should "find" be next to the | or is there a space in there?

The last two lines should be:


compact /u /i /a /s:%%a
)

Right?

I can't even guess what most of the symbols stand for. Is there something I
can read some place?
 
A

Academia

Pegasus (MVP) said:
You could use this batch file:
#@echo off
#set Source=D:\My Files
#echo WScript.Echo Month(Date-30) ^& "/" ^& Day(Date-30) ^& "/" ^&
Year(Date-30)> "%temp%\MyDate.vbs"
#for /F %%a in ('cscript //nologo "%temp%\MyDate.vbs"') do set MyDate=%%a
#
#echo Decompressing all files modified since %MyDate%
#for /F "delims=" %%a in ('xcopy /s /L /d:%MyDate% "%Source%\*.*" c:\ ^|
find ":"') do (
# echo Decompressing "%%a"
#)

Please note:
- Do not retype this file - use copy & paste instead.
- The # characters are there to mark the beginning of each line.
You must remove them before running the batch file.
- Test the file as it is - it won't do anything good or bad.
- After testing the file, add your decompress command right
after the line that says
echo Decompressing "%%a".

Post again if you need an explanation about this code.


I'm posting - I can't figure it out



I moved (without the quotes) "find..." after the | and it didn't work.
so I tried " find..." and again it didn't work.
I get one "Decompressing..\more" message where it looks like the *.* is
replaced with the word "more"

Seems I remember that | is called "pipe". Is that correct?

Looks like xcopy is suppose to build a file in c:\ but what does ^ stand
for?

Will the file go away?

"delims=" doesn't seem to fit the syntax of the For command

I guess () enables you to include a set of commands where the For specifies
one command?


Thanks
 
A

Academia

Ignore last post if you haven't seen it already. When I did For/? I didn't
notice that there was more than the first screen.

I guess what I can't figure out is the code between "in" and "do"

Please see my text below.
I'm posting - I can't figure it out



I moved (without the quotes) "find..." after the | and it didn't work.
so I tried " find..." and again it didn't work.
I get one "Decompressing..\more" message where it looks like the *.* is
replaced with the word "more"

Seems I remember that | is called "pipe". Is that correct?

Looks like xcopy is suppose to build a file in c:\ but what does ^ stand
for?

Will the file go away?
delims="" must turn off the usuall delineters?
 
P

Pegasus \(MVP\)

I assume you refer to the second instance of code between
"in" and "do":
('xcopy /s /L /d:%MyDate% "%Source%\*.*" c:\ ^| find ":"')

This is advanced batch file programming. By preceding the
code with "for /F" and by enclosing the code with single
'quotes' we force this line to be executed:
xcopy /s /L /d:%MyDate% "%Source%\*.*" c:\ ^| find ":"

and for the output of the code to be made available to
the "for" command.

Example:
@echo off
for /F %%a in ('ver') do set version=%%a
This would set "version" to the current version of Windows.

The command
xcopy /s /L /d:%MyDate% "%Source%\*.*" c:\ ^| find ":"
will pretend to copy all files created or modified after %MyDate%.
It will report which files it would copy if we let it, which is
precisely what you're after: A list of files modified after %MyDate%.
Now that you have the names of these files, you can go ahead
and decompress them.
 
A

Academia

I changed to
set Source=C:\Documents and Settings\Joe\junk

Running in a command prompt window I get:
Decompressing "C:\Documents and Settings\Joe\junk\more"
then the command prompt

There is a folder "JUNK" and in it a 0KB file "more" with type "File"
Also many other files.

I don't know why it did "more" first but it appears to have bombed on the
file after "more". In windows explorer the file after has type:
DAT_BAK_83576 File
Note the space between the 6 and the F
The file name is : NTUSER.DAT_BAK_83576

Does any of this mean anything to you?


Thanks
 
A

Academia

Academia said:
I changed to
set Source=C:\Documents and Settings\Joe\junk

Running in a command prompt window I get:
Decompressing "C:\Documents and Settings\Joe\junk\more"
then the command prompt

There is a folder "JUNK" and in it a 0KB file "more" with type "File"
Also many other files.

I don't know why it did "more" first but it appears to have bombed on the
file after "more". In windows explorer the file after has type:
DAT_BAK_83576 File
Note the space between the 6 and the F
The file name is : NTUSER.DAT_BAK_83576

Does any of this mean anything to you?


Thanks

Windows Explorer shows JUNK as read only.
More nor the next file is not.
In Windows Explore I display JUNK's properties, unselect the Readonly box
and click OK
Look at properties agin and Readonly is still set.

In a command window I set default to
C:\Documents and Settings\Joe\

then do
attrib JUNK
and get
C:\Documents and Settings\Joe\JUNK
with no attributes displayed.

Very confusing
 
A

Academia

Academia said:
Windows Explorer shows JUNK as read only.
More nor the next file is not.
In Windows Explore I display JUNK's properties, unselect the Readonly box
and click OK
Look at properties agin and Readonly is still set.

In a command window I set default to
C:\Documents and Settings\Joe\

then do
attrib JUNK
and get
C:\Documents and Settings\Joe\JUNK
with no attributes displayed.
Guessing the above is explained by:
all folders are readonly?


Just found out that NTUSER.DAT_BAK_83576
is compressed. Could that be the problem?
 
P

Pegasus \(MVP\)

Sorry, I cannot make any comments unless you post your
code, complete with markers to show the start of each line.
 
A

Academia

#@echo off
#echo
#echo=================================
#set Source=C:\Documents and Settings\Joe\junk
#echo Decompressing files in %Source%
#
#
#echo WScript.Echo Month(Date-30) ^& "/" ^& Day(Date-30) ^& "/" ^&
Year(Date-30)> "%temp%\MyDate.vbs"
#for /F %%a in ('cscript //nologo "%temp%\MyDate.vbs"') do set MyDate=%%a
#
#echo Decompressing all files modified since %MyDate%
#
#
#echo ================================
#echo Press the Space Bar to continue.
#pause > nul
#
#
#for /F "delims=" %%a in ('xcopy /s /L /d:%MyDate% "%Source%\*.*" c:\ ^|find
":"') do (
# echo Decompressing "%%a"
#)
 
P

Pegasus \(MVP\)

There is nothing wrong with your batch file. To prevent it from
tripping over locked files, add the /c switch to the xcopy command.
Have a look at the output from "xcopy /?" to see what exactly /c
means.

for /F "delims=" %%a in ('xcopy /c /s /L /d:%MyDate% "%Source%\*.*" c:\
^|find ":"') do (
 
A

Academia

My face should be red. There was nothing wrong at all. There is only one
file in the selected tree that had been modified within 30 days so only one
file showed.




I read on the Internet that none of the dates (access, modified, created)
can be trusted because many of the systems files inadvertently change them.
For example, Windows Explorer opens a file to get the icon and thereby
changes the access date. Do you believe this?

Thanks for all the help
 
P

Pegasus \(MVP\)

Academia said:
My face should be red. There was nothing wrong at all. There is only one
file in the selected tree that had been modified within 30 days so only
one file showed.




I read on the Internet that none of the dates (access, modified, created)
can be trusted because many of the systems files inadvertently change
them. For example, Windows Explorer opens a file to get the icon and
thereby changes the access date. Do you believe this?

Thanks for all the help

Sorry, I don't know.
 
A

Academia

Thanks for all the help.

I really need to decompress all files accessed since a given date rather
than changed since a given date.

Doesn't look like XCOPY can do that.

Do you have another suggestion?

Do you think robocopy can be inserted into your code in place of XCOPY?

Would that be something to look into?




Thanks again
 
P

Pegasus \(MVP\)

Academia said:
Thanks for all the help.

I really need to decompress all files accessed since a given date rather
than changed since a given date.

Doesn't look like XCOPY can do that.

Do you have another suggestion?

Do you think robocopy can be inserted into your code in place of XCOPY?

Would that be something to look into?

Thanks again

While it is nice to have a script to do all sorts of fancy things, it
might be appropriate for you to do a proof of concept before
expecting someone else to write that script for you. In your
initial post you said that you wanted to decompress all files
accessed during the past 30 days. I now ask myself the following
questions:
- Why would you need to decompress these files?
- What benefits to expect from this action?
- Have you actually measured these benefits in a reproducible way?
- Can you quantify them?
- Have you considered disabling file compression on this
particular partition?
It might turn out that you gain an estimated five minutes per
month through this script, for an investment of one hour of
someone else's time. Not an attractive proposition . . .
 
A

Academia

In the past I did not have enough space on my system disk so I let disk
cleaner compress.

I now have more space but I am not sure I can decompress the entire disk.

So I'd like to decompress those files that I am using.

You showed me how to decompress those that have been modified which help a
lot.

I was hoping I could modify it by using robocopy to do the rest.

I suspect from your reply that is not going to be easy so I'll let it go for
now.

Thanks for all the help
 
P

Pegasus \(MVP\)

Get a larger disk. They are ridiculously cheap!

Academia said:
In the past I did not have enough space on my system disk so I let disk
cleaner compress.

I now have more space but I am not sure I can decompress the entire disk.

So I'd like to decompress those files that I am using.

You showed me how to decompress those that have been modified which help a
lot.

I was hoping I could modify it by using robocopy to do the rest.

I suspect from your reply that is not going to be easy so I'll let it go
for now.

Thanks for all the help
 
A

Academia

I did, 500GB that why I have some space on the system disk.

I don't think I want to try to copy the system to a new disk.

Besides my system disk is 10000 rpm which are not cheap in the larger sizes.

No problem if decompressing based on last access is difficult to do; I can
do it one folder at a time.

I just thought it would be neater to do only the files being used.

Sounds like a good plan to me. Let the system compress all files not used in
a while.

And occasionally decompress files used lately.

I suppose I could look into a more general script. Maybe vbs.

Anyway, thanks
 
P

Pegasus \(MVP\)

Academia said:
In the past I did not have enough space on my system disk so I let disk
cleaner compress.

I now have more space but I am not sure I can decompress the entire disk.

So I'd like to decompress those files that I am using.

You showed me how to decompress those that have been modified which help a
lot.

I was hoping I could modify it by using robocopy to do the rest.

I suspect from your reply that is not going to be easy so I'll let it go
for now.

Thanks for all the help

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