Articles

Solved recover lost recent saved ~data by batch

February 22, 2013 at 01:29:55
Specs: Windows XP, HexaCore AMD FX-6100, 1400 MHz (7 x 200) / 4gb DDR

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-


See More: recover lost recent saved ~data by batch

Report •


✔ Best Answer
February 26, 2013 at 18:55:16

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.txt

echo 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".



#1
February 22, 2013 at 19:46:37

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.

Report •

#2
February 22, 2013 at 22:13:11

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-


Report •

#3
February 22, 2013 at 22:38:10

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-


Report •

Related Solutions

#4
February 23, 2013 at 09:39:22

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! :-)

Report •

#5
February 24, 2013 at 00:09:54

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-


Report •

#6
February 24, 2013 at 07:21:48

Not mentioned in the OP: These files are typically hidden, so make sure your DIR searches include the /A option.

How To Ask Questions The Smart Way


Report •

#7
February 24, 2013 at 10:29:07

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
:: ==== end

PS 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-


Report •

#8
February 24, 2013 at 22:12:21

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.txt

echo Please wait 6 seconds then press a key && echo. && pause
start notepad.exe hh.txt
cls
:: ==== end

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-


Report •

#9
February 25, 2013 at 19:23:10

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!).

Report •

#10
February 26, 2013 at 01:20:20

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-


Report •

#11
February 26, 2013 at 10:11:50

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...

Report •

#12
February 26, 2013 at 12:59:19

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-


Report •

#13
February 26, 2013 at 18:55:16
✔ Best Answer

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.txt

echo 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".


Report •

#14
February 27, 2013 at 10:15:23

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 key

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-


Report •

#15
February 27, 2013 at 11:35:23

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. :-(

Report •

#16
February 27, 2013 at 11:40:33

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-


Report •

#17
February 27, 2013 at 13:14:17

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.


Report •

#18
February 27, 2013 at 18:44:58

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-


Report •


Ask Question