AutoHotkey Community

It is currently May 26th, 2012, 5:09 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: February 27th, 2009, 9:53 am 
Offline

Joined: April 17th, 2005, 7:47 pm
Posts: 289
Location: Sauerland
This works.
Code:
FullDay = 20000101
FileSetTime, %FullDay%, c:\test.txt

This doesn't. In lieu the file timestamp gets the actual date and time.
Code:
Y = 2000
M = 01
D = 02
FileSetTime, %Y%%M%%D%, c:\test.txt


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 27th, 2009, 10:51 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
Although it doesn't seem to be documented, it appears the first parameter of FileSetTime is an expression. As a result, %Y%%M%%D% is a double-deref. Since no variable with the name 20000102 exists, it gets an empty value. Try using an expression as demonstrated:
Code:
Y = 2000
M = 01
D = 02
FileSetTime, Y M D, c:\test.txt


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 27th, 2009, 3:46 pm 
Offline

Joined: April 17th, 2005, 7:47 pm
Posts: 289
Location: Sauerland
Thanks, it works!

FileSetTime is the only command/function I know, that excepts a traditional and an expression variable.
This is slightly confusing. At least the intended behavior should be documented. :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 28th, 2009, 1:26 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
IIRC, only if(expression) and While(expression) don't support the traditional behaviour. I've tried briefly with WinMove; %var% and var are the same. I know this is also the case for Return. (%var%) and %var1%%var2% are always double-derefs, unlike %var%.

It seems only Return documents this.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 28th, 2009, 2:08 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Since this behavior has been in effect so long, it's probably best to leave it as it is. I've updated the documentation to read:

This parameter is an expression. Consequently, if multiple variables need to be concatenated to form a single timestamp, the dot operator should be used instead of percent signs. For example: FileSetTime, Year . Month . Day, C:\My File.txt

Thanks for reporting it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 28th, 2009, 3:28 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Lexikos wrote:
...with WinMove; %var% and var are the same. I know this is also the case for Return. (%var%) and %var1%%var2% are always double-derefs, unlike %var%.

It seems only Return documents this.

The reason is that parameters that are pure numbers didn't seem to have any need for concatenation like %x%%y% (e.g. not many scripts would concatenate '5' and '6' to form the number 56). When expressions were added to the language, it seemed useful to support them natively in numeric parameters because it could be achieved without sacrificing backward compatibility. This is documented in the Expressions section:
Quote:
...certain parameters of some commands are documented as accepting expressions, in which case the leading percent sign is permitted but not necessary. For example, all of the following are effectively identical because Sleep's first parameter is expression-capable:
Code:
Sleep MillisecondsToWait
Sleep %MillisecondsToWait%
Sleep % MillisecondsToWait

Return's parameter was intended from the beginning to be a pure expression, and there was no need for backward compatibility. Unfortunately, it wasn't discovered until a while afterward that it behaved like it was backward compatible anyway. But rather than risk breaking existing scripts, it was left that way (maybe it was the wrong decision).

Also, since return's behavior was different than users might expect (since return can accept both strings and numbers), this was documented explicitly on its page.

Anyway, it seemed best not to repeat the mistake that was made with return for new syntax like while-loop that is intended to be a pure expression.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 28th, 2009, 3:49 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
Thanks for the detailed explanation. I was aware of some of it, but mostly because I've been through the source code.
Chris wrote:
The reason is that parameters that are pure numbers didn't seem to have any need for concatenation like %x%%y% (e.g. not many scripts would concatenate '5' and '6' to form the number 56).
I guess time stamps are the only exception.
Quote:
This is documented in the Expressions section:
Although it demonstrates %var% and var are equivalent, it doesn't explain that this is an exception to expression syntax. For users that were not familiar with AutoHotkey before expressions were introduced, this might be confusing.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 28th, 2009, 1:08 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Thanks; I've added the following to the expression operator table for percent signs:
Quote:
Also, for backward compatibility, command parameters that are documented as "can be an expression" treat an isolated name in percent signs (e.g. %i%, but not Array%i%) as though the percent signs are absent. This can be avoided by enclosing the reference in parentheses; e.g. Sleep (%Var%)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 28th, 2009, 2:59 pm 
Offline

Joined: April 17th, 2005, 7:47 pm
Posts: 289
Location: Sauerland
Thank you both for clarifying and for updating the documentation!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 5th, 2010, 2:06 am 
Offline

Joined: February 27th, 2009, 9:11 am
Posts: 693
Location: Burbank, California
I thought I understood the previous posts here, but I am still puzzled. Why does this work:
Code:
FormatTime, ts, %oVar2%, yyyyMMddHHmmss
FileSetTime, ts,%a_scriptdir%\%oVar1%

and this does not:
Code:
FileSetTime, oVar2,%a_scriptdir%\%oVar1%

variable oVar2 is in the "yyyyMMddHHmmss" format (actually it is the output of a FileGetTime of another script). I understand that because the 1st parameter is an expression, no %'s are to be used. But oVar2, w/o the %'s, is not recognized and the processed file(s) get today's stamp. Who can shed some light on this???.

_________________
"Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom" but let's start to get the data...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 5th, 2010, 6:31 pm 
Offline

Joined: April 17th, 2005, 7:47 pm
Posts: 289
Location: Sauerland
flyingDman wrote:
and this does not:
Code:
FileSetTime, oVar2,%a_scriptdir%\%oVar1%

variable oVar2 is in the "yyyyMMddHHmmss" format (actually it is the output of a FileGetTime of another script).

This works:
Code:
FileGetTime, oVar2, c:\file1.txt
FileSetTime, oVar2, c:\file2.txt


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 5th, 2010, 10:16 pm 
Offline

Joined: February 27th, 2009, 9:11 am
Posts: 693
Location: Burbank, California
Thank you, that helped me find what the problem was: a simple space ... :oops:

_________________
"Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom" but let's start to get the data...


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group