Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Delete by date

122 views
Skip to first unread message

Andy

unread,
Nov 12, 2012, 3:13:54 PM11/12/12
to
I would like to delete only $NtUninstall directories from 2009.
I am not sure how to do it.

Thanks,
Andy

Todd Vargo

unread,
Nov 12, 2012, 3:58:50 PM11/12/12
to
On 11/12/2012 3:13 PM, Andy wrote:
> I would like to delete only $NtUninstall directories from 2009.
> I am not sure how to do it.

This is a one time process that surely would not require a batch file to
complete. I would simply open explorer, navigate to the folder in
question, set it to detail view, then simply sort the list by date. From
there it is easy enough to select the group of folders needing deleted.

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

Andy

unread,
Nov 12, 2012, 9:36:07 PM11/12/12
to
It would not be a one time event.
I am cleaning up my daughters computer and it's a mess. :-)

Andy

Auric__

unread,
Nov 12, 2012, 11:56:02 PM11/12/12
to
Andy wrote:

> On Monday, November 12, 2012 2:58:51 PM UTC-6, Todd Vargo wrote:
>> On 11/12/2012 3:13 PM, Andy wrote:
>>
>> > I would like to delete only $NtUninstall directories from 2009.
>> > I am not sure how to do it.
>>
>> This is a one time process that surely would not require a batch file to
>> complete. I would simply open explorer, navigate to the folder in
>> question, set it to detail view, then simply sort the list by date. From
>> there it is easy enough to select the group of folders needing deleted.
>
> It would not be a one time event.
> I am cleaning up my daughters computer and it's a mess. :-)

Unless your daughter has several computers laying around, or keeps her
system's clock set to 2009 during updates, it's *definitely* a 1-time thing.
Todd's method is *exactly* how I would do it.

--
Nothing spells "imminent trauma" like a group of bored teenage boys.

Andy

unread,
Nov 13, 2012, 12:00:45 PM11/13/12
to
I love learning and I think modifying this might work.

Take care,
Andy

@Echo Off
:: Code by OutCaste,
FOR /D /R c:\test %%X IN (now*.) DO RD /S /Q "%%X"
goto :EOF
Set _TabSpace=
Setlocal EnableDelayedExpansion
:: User Variables
:: Set this to the number of days you want to keep
Set _DaysKept=800
:: Set this to the folder that contains the folders to check and delete
Set _Path=C:\Test1
:: Get todays date
Call :GetDate
Set _yy=%_fDate:~,4%
Set _mm=%_fDate:~4,2%
Set _dd=%_fDate:~6,2%
:: Convert todays date to Julian
Call :JDate %_yy% %_mm% %_dd%
Set _JToday=%_JDate%
:: Set delete date
Set /a _DelDate=_JToday-%_DaysKept%-1
:: Get time format, _iTime will be 0 if 12 hourt clock, 1 if 24 hour clock
:: Delims= is a TAB followed by a space in the next line
For /F "TOKENS=2* DELIMS=%_TabSpace%" %%A In ('REG QUERY "HKCU\Control Panel\International" /v iTime') Do Set _iTime=%%B
If Exist "%temp%\tf}1{" Del "%temp%\tf}1{"
PushD %_Path%
Set _s=s
If %_DaysKept%==1 set _s=
Echo Please wait, searching for folders more than %_DaysKept% day%_s% old
If %_iTime%==0 (Set _Tok=1,4*) Else (Set _Tok=1,3*)
For /F "tokens=%_Tok% skip=4" %%I In ('dir "%_Path%\1*" /AD /OD /TW ^|Findstr /E "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]"') Do (
Set _Name=%%K
If "!_Name:~10!"=="" If %%J==^<DIR^> (
Call :GetDate %%I
Call :JDate !_fDate:~,4! !_fDate:~4,2! !_fDate:~6,2!
If !_JDate! LEQ %_DelDate% (
If Exist "%temp%\tf}1{" (
Echo %%I:%%~fK >>"%temp%\tf}1{"
) Else (
Echo.>"%temp%\tf}1{"
Echo Do you wish to delete the following folders?>>"%temp%\tf}1{"
Echo Date Name>>"%temp%\tf}1{"
Echo %%I:%%~fK >>"%temp%\tf}1{"
)) Else (
Goto :_allFound
)))
PopD
:_allFound
If Not Exist "%temp%\tf}1{" Echo No Folders Found to delete&Goto _Done
Type "%temp%\tf}1{" | More
Set _rdflag= /q
:_Prompt1
Set /P _resp=Delete All, None, or Prompt for each (A/N/P)?
If /I "%_resp:~0,1%"=="N" Goto _Done
If /I "%_resp:~0,1%"=="A" Goto _Removeold
If /I NOT "%_resp:~0,1%"=="P" (Echo (A/N/P only please)&Goto _Prompt1
Set _rdflag=
:_Removeold
For /F "tokens=1* skip=3 Delims=:" %%I In ('type "%temp%\tf}1{"') Do (
If "%_rdflag%"=="" Echo Deleting
rd /s%_rdflag% "%%J")
:_Done
If Exist "%temp%\tf}1{" Del "%temp%\tf}1{"
Goto:EOF
::===================================::
:: ::
:: - S u b r o u t i n e s - ::
:: ::
::===================================::
:JDate
:: Convert date to Julian
:: Arguments : YYYY MM DD
:: Returns : Julian date in variable _JDate
:: Usage
::Call :JDate %__GYear% %_GMonth% %_GDay%
:: First strip leading zeroes; a logical error in this
:: routine was corrected with help from Alexander Shapiro
::Code taken from datediff.bat written by Rob van der Woude
::http://www.robvanderwoude.com
Set _JMM=%2
Set _JDD=%3
IF 1%_JMM% LSS 110 Set _JMM=%_JMM:~1%
IF 1%_JDD% LSS 110 Set _JDD=%_JDD:~1%
::
:: Algorithm based on Fliegel-Van Flandern
:: algorithm from the Astronomical Almanac,
:: provided by Doctor Fenton on the Math Forum
:: (http://mathforum.org/library/drmath/view/51907.html),
:: and converted to batch code by Ron Bakowski.
Set /A _JMonth1 = ( %_JMM% - 14 ) / 12
Set /A _JYear1 = %1 + 4800
Set /A _JDate = 1461 * ( %_JYear1% + %_JMonth1% ) / 4 + 367 * ( %_JMM% - 2 -12 * %_JMonth1% ) / 12 - ( 3 * ( ( %_JYear1% + %_JMonth1% + 100 ) / 100 ) ) / 4 + %_JDD% - 32075
For %%A In (_JMonth1 _JYear1) Do Set %%A=
Goto:EOF
:GetDate
:: This subroutine will always display the same results,
:: for the date independent of "International" settings.
:: This batch file uses REG.EXE from the NT Resource Kit
:: (already installed with WinXP and Vista)
:: to read the "International" settings from the registry.
:: Date is returned as yyyymmdd in variable _fdate
:: Modified from SortDate Written by Rob van der Woude
:: http://www.robvanderwoude.com
::
If NOT [%1]==[] Set Date=%1
If "%date%A" LSS "A" (Set _NumTok=1-3) Else (Set _NumTok=2-4)
:: Delims= is a TAB followed by a space in the next two lines
For /F "SKIP=3 TOKENS=2* DELIMS=%_TabSpace%" %%A In ('REG QUERY "HKCU\Control Panel\International" /v iDate') Do Set _iDate=%%B
For /F "SKIP=3 TOKENS=2* DELIMS=%_TabSpace%" %%A In ('REG QUERY "HKCU\Control Panel\International" /v sDate') Do Set _sDate=%%B
IF %_iDate%==0 For /F "TOKENS=%_NumTok% DELIMS=%_sDate% " %%B In ("%date%") Do Set _fdate=%%D%%B%%C
IF %_iDate%==1 For /F "TOKENS=%_NumTok% DELIMS=%_sDate% " %%B In ("%date%") Do Set _fdate=%%D%%C%%B
IF %_iDate%==2 For /F "TOKENS=%_NumTok% DELIMS=%_sDate% " %%B In ("%date%") Do Set _fdate=%%B%%C%%D
Goto:EOF

foxidrive

unread,
Nov 13, 2012, 12:37:04 PM11/13/12
to
On 14/11/2012 04:00, Andy wrote:
>>
>>>>> I would like to delete only $NtUninstall directories from 2009.
>>
>>>>> I am not sure how to do it.

> I love learning and I think modifying this might work.

or you could do this.

@echo off
pushd "%windir%"
for /f %%a in ('dir $NtUninstall* /ad /b') do (
echo "%%~ta"|find "2009" >nul && echo rd /s /q "%%a"
)
popd




--
foxi

Andy

unread,
Nov 13, 2012, 1:14:19 PM11/13/12
to
Thanks foxi.

Andy

Andy

unread,
Nov 13, 2012, 2:41:30 PM11/13/12
to
On Tuesday, November 13, 2012 11:37:07 AM UTC-6, foxidrive wrote:
Almost there. It can't delete the directories because the names are surrounded by quotes.

Andy

foxidrive

unread,
Nov 13, 2012, 6:40:12 PM11/13/12
to
That's not the reason. You need admin permissions I would assume.


--
foxi

foxidrive

unread,
Nov 13, 2012, 6:40:57 PM11/13/12
to
On 14/11/2012 06:41, Andy wrote:
You did remember to remove the echo, didn't you?


--
foxi

Todd Vargo

unread,
Nov 13, 2012, 7:36:41 PM11/13/12
to
But modifying the bloated concoction from OutCaste is so much easier. LOL!

BTW, you forgot to include 10 lines of self credit to make it look more
sophisticated. :^)

Andy

unread,
Nov 13, 2012, 9:27:09 PM11/13/12
to
Todd, you are so cool.

Andy

Andy

unread,
Nov 14, 2012, 8:49:17 PM11/14/12
to
@echo off
::pushd "%windir%"
pushd c:\z_keep
for /f %%a in ('dir test* /ad /b') do ("%%~ta"|find "2013" >nul && rd /s /q "%%a")
popd

The system cannot find the path specified.

I noticed than doing an echo to a text file didn't work to capture the error.

foxidrive

unread,
Nov 14, 2012, 10:15:37 PM11/14/12
to
On 15/11/2012 12:49, Andy wrote:

> @echo off
> ::pushd "%windir%"
> pushd c:\z_keep
> for /f %%a in ('dir test* /ad /b') do ("%%~ta"|find "2013" >nul && rd /s /q "%%a")
> popd
>
> The system cannot find the path specified.
>

That's because you wrote the code incorrectly. Try copy and pasting it again.


> I noticed than doing an echo to a text file didn't work to capture the error.

You need to capture STDERR by redirecting the 2 stream. 2>error.txt



--
foxi

Todd Vargo

unread,
Nov 15, 2012, 1:26:39 AM11/15/12
to
Also, I doubt any files from 2013 would be found on 15/11/2012.

Andy

unread,
Nov 15, 2012, 9:12:05 AM11/15/12
to
I copied it and removed only the echos.

It tries to remove the right directories, but the dir names are surrounded by double quotes, and are not removed.

Andy

foxidrive

unread,
Nov 15, 2012, 9:28:48 AM11/15/12
to
The echo is needed for it to work. Why did you remove it without instructions to remove it, one would
wonder. :)




--
foxi

foxidrive

unread,
Nov 15, 2012, 9:30:31 AM11/15/12
to
On 16/11/2012 01:12, Andy wrote:
My error. There were two echos and yes the second one needed to be removed, but not the first one.

Try it with the first echo in place.




--
foxi

Andy

unread,
Nov 15, 2012, 10:37:00 AM11/15/12
to
> foxi

Thanks, it works great.

Andy

Dr J R Stockton

unread,
Nov 15, 2012, 4:11:59 PM11/15/12
to
In alt.msdos.batch.nt message <f44c37a9-4520-4437-9910-ecac5cf6f738@goog
legroups.com>, Mon, 12 Nov 2012 12:13:54, Andy
<chocolate...@yahoo.com> posted:

>I would like to delete only $NtUninstall directories from 2009.
>I am not sure how to do it.

That depends on what you mean by 2009.

HUNT, via sig line 3, in 16 & 32 bit systems, will do it using the "DOS"
datestamp. Frequently used for two decades.

SEEK / SEAKFYLE, via sig line 3 32-bit subdirectory, should be able to
do it in 32 or 64 bit systems using any of the three dates. Recent;
tested; little used.

CAVEAT for users with Summer Time at year rollover - apparent directory
dates might be an hour wrong (0.5 hour for LHI, if Microsoft knew of the
place).

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk DOS 3.3, 6.20; WinXP.
Web <http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms and links.
PAS EXE TXT ZIP via <http://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS <http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.

Dr J R Stockton

unread,
Nov 16, 2012, 2:50:58 PM11/16/12
to
In alt.msdos.batch.nt message <k821uu$gis$2...@news.albasani.net>, Thu, 15
Nov 2012 01:26:39, Todd Vargo <tlv...@sbcglobal.netz> posted:

>
>Also, I doubt any files from 2013 would be found on 15/11/2012.
>

In this international medium, ISO 8601 dates should be used. Since I
think you are American, that date must mean Day 11 of Month 15 of 2012,
which is 2013-03-15 ...

<http://www.merlyn.demon.co.uk/zipfiles/hunttest.zip> contains zero-
length files with various datestamps, ranging from 1980-00-00 00:00:00
to 2107-15-31 31:63:62 IIRC - but read those rated with reliable DOS
tools, not with lying GUI stuff. It includes a TXT file.

--
(c) John Stockton, nr London UK. Mail, see Homepage. BP7, Delphi 3 & 2006.
<http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
<http://www.bancoems.com/CompLangPascalDelphiMisc-MiniFAQ.htm> clpdmFAQ;
NOT <http://support.codegear.com/newsgroups/>: news:borland.* Guidelines

Todd Vargo

unread,
Nov 16, 2012, 11:00:58 PM11/16/12
to
On 11/16/2012 2:50 PM, Dr J R Stockton wrote:
> In alt.msdos.batch.nt message <k821uu$gis$2...@news.albasani.net>, Thu, 15
> Nov 2012 01:26:39, Todd Vargo <tlv...@sbcglobal.netz> posted:
>
>>
>> Also, I doubt any files from 2013 would be found on 15/11/2012.
>>
>
> In this international medium, ISO 8601 dates should be used. Since I
> think you are American, that date must mean Day 11 of Month 15 of 2012,
> which is 2013-03-15 ...

Poor John, always playing the fool. Perhaps if you bother to examine the
quoted lines at the top of my post (you know, the portion you snipped),
you might realize I copied it from foxi's post in response to same.

>
> <http://www.merlyn.demon.co.uk/zipfiles/hunttest.zip> contains zero-
> length files with various datestamps, ranging from 1980-00-00 00:00:00
> to 2107-15-31 31:63:62 IIRC - but read those rated with reliable DOS
> tools, not with lying GUI stuff. It includes a TXT file.

More *irrelevant* drivel. Not related to this discussion.
Don't troll (tread) on me!

Dr J R Stockton

unread,
Nov 18, 2012, 1:57:57 PM11/18/12
to
In alt.msdos.batch.nt message <k8725r$lee$1...@news.albasani.net>, Fri, 16
Nov 2012 23:00:58, Todd Vargo <tlv...@sbcglobal.netz> posted:

>On 11/16/2012 2:50 PM, Dr J R Stockton wrote:
>> In alt.msdos.batch.nt message <k821uu$gis$2...@news.albasani.net>, Thu, 15
>> Nov 2012 01:26:39, Todd Vargo <tlv...@sbcglobal.netz> posted:
>>
>>>
>>> Also, I doubt any files from 2013 would be found on 15/11/2012.
>>>
>>
>> In this international medium, ISO 8601 dates should be used. Since I
>> think you are American, that date must mean Day 11 of Month 15 of 2012,
>> which is 2013-03-15 ...
>
>Poor John, always playing the fool. Perhaps if you bother to examine
>the quoted lines at the top of my post (you know, the portion you
>snipped), you might realize I copied it from foxi's post in response to
>same.

You are responsible for what you copy, unless indicated by standard
quoting methods or conspicuously otherwise. Reproducing an attribution
verbatim, with an extra quote character, is standard; extracting
substrings is not.

>> <http://www.merlyn.demon.co.uk/zipfiles/hunttest.zip> contains zero-
>> length files with various datestamps, ranging from 1980-00-00 00:00:00
>> to 2107-15-31 31:63:62 IIRC - but read those rated with reliable DOS
>> tools, not with lying GUI stuff. It includes a TXT file.
>
>More *irrelevant* drivel. Not related to this discussion.
>Don't troll (tread) on me!

Were US education better, you might have become a half-wit. You are
doubting whether future-dated files are liable to exist in a computer; I
give there a counter-example.

There is no need to allow for the strictly impossible; but true DOS file
datestamps can have any value, in even seconds, between those above,
inclusive.

--
(c) John Stockton, nr London, UK. E-mail, see Home Page. Turnpike v6.05.
Website <http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc. : <http://www.merlyn.demon.co.uk/programs/> - see in 00index.htm
Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.
0 new messages