I keep hearing from friends, who spend hours writing letters, or creating PDF, documents and LOSE all their work often the application they are using crashes or the PC hangs up, in most often situation the file was saved as something like ~mydoc.ext or mydoc.tm~ does anyone have some simple batch code that can search for ALL recent saved files in the .docx .doc. pdf .ect ranges and only look for documents created or modified in the last say 6 hours ? something to search all the users local document profile locations and then re-save what it finds in a folder called found docs, on the desktop ? Must be able to run on any windows OS Thanks Michelle xxx
If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://www.book-stores.com/angels-

Apologies, I just tendered it as a "prototype/test/addon" to be run against the sorted list of found files (in hh). I'll integrate it into the existing arrangement "on the fly" instead of a "retro-fit". The vbscript is independant, so I won't re-post that, just the batch:
@echo off>\h & setlocal enabledelayedexpansion
echo PLEASE ENTER FILE NAME OR WILDCARDS BELOW.
echo.
set myvari=
set /P myvari=Set Search Terms Here i.e. *.bmp OR *.pdf [etc]?
:: first part of the integration
set hrs=
set /p hrs=Enter number of hours to regress for examining files:
for /f "tokens=*" %%a in ('cscript /nologo da.vbs -%hrs%') do set test=%%a
set exclude=
set o=
set /p exclude=enter quoted,comma-sep list of anything to be excluded:
if defined exclude call :exc %exclude%>exclude
cls
echo SEARCHING FOR %myvari% CUTOFF DATE/TIME: %test%
for /f "tokens=*" %%a in ('dir /a /b /s %myvari%') do (
for /f "tokens=1-4* delims=/ " %%b in ("%%~ta") do set d=%%d-%%b-%%c %%e
:: here's the second part of the integration
if "!d!" geq "%test%">> \h echo !d! %%~pnxa
)
sort /r \h%o% > hh.txtecho Please wait 6 seconds then press a key && echo. && pause
start notepad.exe hh.txt
cls
goto :eof:exc
if "%~1" equ "" goto :exx
echo %~1
shift
goto :exc
:exx
set o=^|findstr /i /v /g:exclude
:: ==== end
the only disadvantage is, if the enduser wants to try a more inclusive "time-filter", they will have to re-run the entire directory-search to rebuild file "hh".
Hello again Friend: This basic listing might be sufficient, depending on how many files have been generated. I haven't tried any filters, just a sort:
@echo off & setlocal enabledelayedexpansion
:: pushd to root of wherever these might be found
pushd %userprofile%
:: if you know specific extension, you can filter them here:
::for /f "tokens=*" %%a in ('dir /b /s' *.doc *.docx *.tmp *.tm~ mypdf.*) do (
for /f "tokens=*" %%a in ('dir /b /s') do (
:: build a date-time-sortable file with full paths
for /f "tokens=1-4* delims=/ " %%b in ("%%~ta") do set d=%%d-%%b-%%c %%e
>> \h echo !d! %%~pnxa
)
:: all newest files will be at top
sort /r \h > \help
edit help
popd
::===== end snippet
I won't dignify this as a "solution", but it might be a constructive half-measure. Usually my volume of files is such that I can just scan a time-sorted list and pick out what might be my target, based on name and timestamp. Also, any filters have a chance of missing something unexpected, but if the volume is too high, they might be needed. I sure hope this helps, I know the feeling of lost data. Before the ntfs, I was able to scan my entire disk (sector-by-sector) for a string, and actually recovered a couple of lost items that way.
Your Amazing nbrane, this will mean so much to people like Miriam who work hard and often lose data a BIG THANK YOU <3 Michelle xxx
If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://www.book-stores.com/angels-
Just running tests on my own system, it did not find anything in Sub directories is the switch for this /s ? Michelle
PS ahhh i'm getting an error message!
The system cannot find the file 'dir /b /s' *.doc *.docx *.tmp *.tm~ *.pd~ *.av~
.
\hThe system cannot find the file specified.
Press any key to continue . . .
If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://www.book-stores.com/angels-
Hello Michelle: it worked in my tests, with or without the filters:
@echo off>\h & setlocal enabledelayedexpansion
for /f "tokens=*" %%a in ('dir /b /s da* ort* *.txt') do (
for /f "tokens=1-4* delims=/ " %%b in ("%%~ta") do set d=%%d-%%b-%%c %%e
>> \h echo !d! %%~pnxa
)
sort /r \h > \hh
::==== end
I just used the root for the tempfiles (\h, \hh) which is not always a good idea, I was just in a hurry and didn't want to put the "h" files anywhere in the path of the target directory. I hate working with paths, especially on other peoples systems, and about half the errors are due to path conflicts and problems. I also should not have used "help" for a filename, that was plain dumb of me. It has too much chance of being an existing file or directory. Hope this helps. If you continue having problems, please first check the paths and names of the temp output files (h, hh), and p-mail me back with the exact commandline or batch that is failing. Good luck! :-)
Thanks nbrane, might not be working for me because my system is too clean I always clear my cache everyday will ask a friend to try it out, also I just went back to an earlier copy of my windows without office installed on it as found it was conflicting with some programs perhaps so will have to run more tests here thanks. To test it I used some known temp files I know do exist ~*.tmp *.tmp
but still nothing was found oh well we tried :)Michelle
If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://www.book-stores.com/angels-
Not mentioned in the OP: These files are typically hidden, so make sure your DIR searches include the /A option.
Thanks Razor will try that :) Like this ?
@echo off>\h & setlocal enabledelayedexpansion
for /f "tokens=*" %%a in ('dir /a /b /s da* ~*.tmp *.tmp') do (
for /f "tokens=1-4* delims=/ " %%b in ("%%~ta") do set d=%%d-%%b-%%c %%e
>> \h echo !d! %%~pnxa
)
sort /r \h > \hh.txt
start notepad hh.txt
if exist sleep.com sleep 10
cls
:: ==== endPS I found out why it was not working for me, silly me was running the batch on drive D: It never occurred to me that it needed to be on my C: drive lol now I am getting lots of found items.
Now to limit results just need to limit the results to about 6 hours or 1 day.
Michelle xxx
If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://www.book-stores.com/angels-
Dear nbrane, Just added a prompt @echo off>\h & setlocal enabledelayedexpansion
echo PLEASE ENTER FILE NAME OR WILDCARDS BELOW.
echo.
set /P myvari=Set Search Terms Here i.e. *.bmp OR *.pdf [etc]?
cls
echo SEARCHING FOR %myvari%
for /f "tokens=*" %%a in ('dir /a /b /s %myvari%') do (
for /f "tokens=1-4* delims=/ " %%b in ("%%~ta") do set d=%%d-%%b-%%c %%e
>> \h echo !d! %%~pnxa
)
sort /r \h > hh.txtecho Please wait 6 seconds then press a key && echo. && pause
start notepad.exe hh.txt
cls
:: ==== endIf Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://www.book-stores.com/angels-
Sorry for not replying sooner, my internet access has been down for two days.
Sounds like you've got it working except for the 6-hour deal, which gets complicated. (Which would be why I, being lazy, chose to avoid it using a "sort"). Because if the 6-hour span crosses a day, then you have to adjust for that as well. I think there's an easy way to do it, but maybe not with batch. We could always "find" the current day, and the current day minus one, getting within 48 hours of the target-limit, but then you get into date formats (yech!).
Yes a day would probably work, I have got some date stuff saved in my other batch files just don't know how to do the subtracting stuff, only reason really is to limit a flood as I know many peoples computers are full of a lot of junk and it helps weed out stuff that is too old or not relevant to the quick search of a lost file that just happened, But if its too complex we can just not bother with that I guess.
Michelle xxx
If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://www.book-stores.com/angels-
hello again! Ok, here's what I've got. It's ugly, but it works ok:
::===== first, the batchscript add-on
@echo off>\h & setlocal
set /p hrs=
set /p hrs=Enter number of hours to regress for examining files:
for /f "tokens=*" %%a in ('cscript /nologo da.vbs -%hrs%') do set test=%%a
for /f "tokens=*" %%a in (\hh) do (
if "%test%" gtr "%%a" goto :eof
>> \h echo %%a
)
::==== end batch, begin vbscript "da.vbs" or whatever name used in above bat
z=dateadd("h",wscript.arguments(0),date)
y=dateadd("h",wscript.arguments(0),time)
x=formatdatetime(y,4)
n=split(formatdatetime(z,2),"/")
for i=0 to 1
n(i)=right("0"+n(i),2)
next
z=n(2)+"-"+n(0)+"-"+n(1)
wscript.echo z,x
'===== end vbscript
I just recycled work-file "h" for holding the final output.
batch is not recommended for handling date-math. I wasted many hours, when i first started out, writing scripts to handle it, and it's just not very practical or rewarding to re-invent a square wheel when the round ones work so much better!
Try this and let me know...
Dear nbrane thanks for that but not sure where to insert it into my existing batch file @ message #8 tried it at the end but nothing happens ? Michelle
If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://www.book-stores.com/angels-
Apologies, I just tendered it as a "prototype/test/addon" to be run against the sorted list of found files (in hh). I'll integrate it into the existing arrangement "on the fly" instead of a "retro-fit". The vbscript is independant, so I won't re-post that, just the batch:
@echo off>\h & setlocal enabledelayedexpansion
echo PLEASE ENTER FILE NAME OR WILDCARDS BELOW.
echo.
set myvari=
set /P myvari=Set Search Terms Here i.e. *.bmp OR *.pdf [etc]?
:: first part of the integration
set hrs=
set /p hrs=Enter number of hours to regress for examining files:
for /f "tokens=*" %%a in ('cscript /nologo da.vbs -%hrs%') do set test=%%a
set exclude=
set o=
set /p exclude=enter quoted,comma-sep list of anything to be excluded:
if defined exclude call :exc %exclude%>exclude
cls
echo SEARCHING FOR %myvari% CUTOFF DATE/TIME: %test%
for /f "tokens=*" %%a in ('dir /a /b /s %myvari%') do (
for /f "tokens=1-4* delims=/ " %%b in ("%%~ta") do set d=%%d-%%b-%%c %%e
:: here's the second part of the integration
if "!d!" geq "%test%">> \h echo !d! %%~pnxa
)
sort /r \h%o% > hh.txtecho Please wait 6 seconds then press a key && echo. && pause
start notepad.exe hh.txt
cls
goto :eof:exc
if "%~1" equ "" goto :exx
echo %~1
shift
goto :exc
:exx
set o=^|findstr /i /v /g:exclude
:: ==== end
the only disadvantage is, if the enduser wants to try a more inclusive "time-filter", they will have to re-run the entire directory-search to rebuild file "hh".
Thanks nbrane will try this was too tired last night thanks <3 Michelle
OK Just ran the script in the root of drive C: this is the output I got.
SEARCHING FOR *.txt CUTOFF DATE/TIME: 2013-26-02 06:24
The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
Please wait 6 seconds then press a keyPress any key to continue . . .
If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://www.book-stores.com/angels-
I'm sorry (again). just put quotes here:
if "!d!" geq "%test%">> \h echo !d! %%~pnxa
rather than re-posting the entire script, I'll fix it in my previous response. I should have tested it last night. :-(
Thanks nbrane, its ok I have not been very focussed myself the last few days rather fuzzy headed I never realised they were paths thanks will try that <3 Michelle
PS It works awesome :)
If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://www.book-stores.com/angels-
Thanks! I also added one further refinement, taking into consideration there may be large areas that do NOT have a chance of holding the desired files, which could clutter up the output, such as cache files from an internet session. I built that into response #13. But, most importantly, I fixed a major bug at this line:
set /p hrs=
set /p hrs=Enter number of hours to regress for examining files:should be no "/p" in the first statement:
set hrs=
set /p hrs=Enter number of hours to regress for examining files:
(I kept wondering why it hung up there).
If you have any questions, just holler at me.
In fact I was wondering about that, when I first ran the batch it sat their for 5 minutes before I realised it was waiting for input lol, I did not want to hurt your feelings so just commented out the first set /p hrs= Now it makes sense that it was meant to zero out and old settings thanks nbrane, in fact I am sure this will be a handy tool also to look for potential virus's as well if stuff is written recently perhaps!
Michelle xxx
If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://www.book-stores.com/angels-
