AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

FileSetTime doesn't work with composite parameters.

 
Reply to topic    AutoHotkey Community Forum Index -> Bug Reports
View previous topic :: View next topic  
Author Message
Rabiator



Joined: 17 Apr 2005
Posts: 289
Location: Sauerland

PostPosted: Fri Feb 27, 2009 8:53 am    Post subject: FileSetTime doesn't work with composite parameters. Reply with quote

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
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 7295
Location: Australia

PostPosted: Fri Feb 27, 2009 9:51 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
Rabiator



Joined: 17 Apr 2005
Posts: 289
Location: Sauerland

PostPosted: Fri Feb 27, 2009 2:46 pm    Post subject: Reply with quote

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. Smile
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 7295
Location: Australia

PostPosted: Sat Feb 28, 2009 12:26 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Visit poster's website
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10716

PostPosted: Sat Feb 28, 2009 1:08 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Send e-mail
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10716

PostPosted: Sat Feb 28, 2009 2:28 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Send e-mail
Lexikos



Joined: 17 Oct 2006
Posts: 7295
Location: Australia

PostPosted: Sat Feb 28, 2009 2:49 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Visit poster's website
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10716

PostPosted: Sat Feb 28, 2009 12:08 pm    Post subject: Reply with quote

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%)
Back to top
View user's profile Send private message Send e-mail
Rabiator



Joined: 17 Apr 2005
Posts: 289
Location: Sauerland

PostPosted: Sat Feb 28, 2009 1:59 pm    Post subject: Reply with quote

Thank you both for clarifying and for updating the documentation!
Back to top
View user's profile Send private message
flyingDman



Joined: 27 Feb 2009
Posts: 690
Location: Burbank, California

PostPosted: Fri Mar 05, 2010 1:06 am    Post subject: Reply with quote

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...
Back to top
View user's profile Send private message
Rabiator



Joined: 17 Apr 2005
Posts: 289
Location: Sauerland

PostPosted: Fri Mar 05, 2010 5:31 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
flyingDman



Joined: 27 Feb 2009
Posts: 690
Location: Burbank, California

PostPosted: Fri Mar 05, 2010 9:16 pm    Post subject: Reply with quote

Thank you, that helped me find what the problem was: a simple space ... Embarassed
_________________
"Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom" but let's start to get the data...
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Bug Reports All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group