Home / Microsoft / Microsoft DOS / Decypher file attribute in a FOR loop
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: 1 [2]  All - (Bottom) Print
Author Topic: Decypher file attribute in a FOR loop  (Read 965 times)
kwc1059
Topic Starter
Greenhorn



Posts: 6


« Reply #15 on: November 19, 2009, 02:28:09 PM »

My tests on the attribute variable seemed to work but I will give your suggestion a try.

Code: [Select]
if %mm% GTR 01 set /a jd1=%jd1%+31
I am creating two dates in the format yyyyddd.  I start by taking the year and multiplying by 1000.  Then I have to add days based on the month.  If the month is March then I need to add the days for January and February.  Then I add the day for the date in question. 

For eample, suppose the date is 03/15/2009.  I take the year and multiply by 1000 getting 2009000.  The month is greater than 1 so I add 31 days for January.  The month is greater than 2 so I add 28 days for February (yes, I do not account for leap year).  The month is not greater than 3 so it falls through the rest of the "if" statements.  I then add the current day.  Now the date is 2009074.   

The "if" statement for greater than 12 will never be true and should be deleted.



IP logged
Salmon Trout
Prodigy



Thanked: 501
Posts: 7,367

Computer: Specs
Experience: Guru
OS: Linux variant

1
« Reply #16 on: November 19, 2009, 04:01:41 PM »

Quote from: kwc1059
I am creating two dates in the format yyyyddd.  I start by taking the year and multiplying by 1000

You may find these scripts useful

http://www.commandline.co.uk/cmdfuncs/dandt/index.html

Also, VBscript has built in date math functions. You can use them from batch, if VBscripts are allowed on your system

Code: [Select]
@echo off

REM Create VBscript
echo wsh.echo Year(wscript.arguments(0))^&DatePart("y", wscript.arguments(0))>Daynumber.vbs

REM now you can use it in your script as many times as you want

set querydate1=20/11/2009

REM pass the date to the VBscript & get back the result
for /f "delims==" %%D in ('cscript //nologo Daynumber.vbs %querydate1%') do set Daynumber1=%%D

set querydate2=20/03/2009

for /f "delims==" %%D in ('cscript //nologo Daynumber.vbs %querydate2%') do set Daynumber2=%%D

echo The day number of %querydate1% is %Daynumber1%
echo The day number of %querydate2% is %Daynumber2%

output

Code: [Select]
The day number of 20/11/2009 is 2009324
The day number of 20/03/2009 is 200979

As you can see, my system uses the European dd/mm/yyyy format for dates but I believe that if your system locale settings are US you would find that 11/19/2009 would give you 2009323 but you would have to try that yourself.

« Last Edit: November 20, 2009, 12:10:47 AM by Salmon Trout » IP logged

billrich
Guest
« Reply #17 on: November 19, 2009, 04:41:39 PM »

Hello
« Last Edit: November 21, 2009, 10:36:54 PM by billrich » IP logged
Pages: 1 [2]  All - (Top) Print 
Home / Microsoft / Microsoft DOS / Decypher file attribute in a FOR loop « previous next »
 


Login with username, password and session length

Old Forum Search | Forum Rules
Copyright © 2010 Computer Hope ® All rights reserved.
Powered by SMF 2.0 RC3 | SMF © 2006–2010, Simple Machines LLC
Page created in 0.075 seconds with 20 queries.