SetAttrib date to 'Current' in a single click?

English support forum

Moderators: white, Hacker, petermad, Stefan2

hooly
Junior Member
Junior Member
Posts: 15
Joined: 2008-05-26, 06:53 UTC

SetAttrib date to 'Current' in a single click?

Post by *hooly »

please excuse what i'm sure is a noobie question but how would i do this? i know how to set up a button to trigger cm_SetAttrib but it's not obvious how i would tell it to automatically do the "Change Date/Time" to "Current" and go do it. of course the idea is that i just want to point and shoot, not have to deal with the dialog box.

the goal of course is to do like what unix's 'touch' command does by default, namely just update the timestamp of the file to the computer's current date and time, whatever that happens to be. (see touch (Unix) - Wikipedia, the free encyclopedia for reference).
User avatar
ZoSTeR
Power Member
Power Member
Posts: 1013
Joined: 2004-07-29, 11:00 UTC

Post by *ZoSTeR »

You can get a Windows version of touch here: http://sourceforge.net/projects/unxutils

Then create a button with %P%N
User avatar
tuska
Power Member
Power Member
Posts: 3760
Joined: 2007-05-21, 12:17 UTC

Post by *tuska »

Hello,
I have installed touch.exe on a button and it works well.
Unfortunately changes of attributes are only possible file by file.
Does anyone know a solution in which several files could be marked and attributes will changed with one click to current date/time?
Gruß,
Karl
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

You may use simple BAT file:

Code: Select all

@echo off 
if -%1==- echo Parameters: "%%WL"&pause &goto :EOF 

if -%1==-go goto do_work 
for /f "usebackq delims=" %%f in (`type %1`) do call %0 go "%%f" %2 
pause 
goto :EOF 

:do_work
touch.exe %2
Write full path to touch.exe, add batch file to buttonbar, set "%WL" as button parameter. Batch will call touch for every selected item in panel.
Last edited by MVV on 2011-06-20, 17:57 UTC, edited 2 times in total.
hooly
Junior Member
Junior Member
Posts: 15
Joined: 2008-05-26, 06:53 UTC

Post by *hooly »

tuska wrote:Does anyone know a solution in which several files could be marked and attributes will changed with one click to current date/time?
exactly what i'm looking for too. sounds like maybe a script is what's required here. anyone got such a thing? for AHK would be ideal, imo.

... or the one MVV just posted sounds good too (came in as i was typing my post).
User avatar
tuska
Power Member
Power Member
Posts: 3760
Joined: 2007-05-21, 12:17 UTC

Post by *tuska »

Thanks a lot MVV!
works very good - I have only one litte additional question: The batchfile calls the DOS-Box and at the end the DOS-window does not close automatically.
Do you see any possibility to solve this problem- but I don't want you to take too much time on this problem.
I am very happy with your batchfile - thanks again.
Gruß,
Karl
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Hm-m, it shouldn't launch DOSBox at all, Windows should execute it directly. It seems that you have associated .bat files with DOSBox, try to rename batch to .cmd - it is also extension for command files, maybe .cmd files have right association in your system.
User avatar
tuska
Power Member
Power Member
Posts: 3760
Joined: 2007-05-21, 12:17 UTC

Post by *tuska »

I have changed from .bat to .cmd - DOSBox remained.
So I would let it as it is - no problem to push the blank key.
Gruß,
Karl
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

You may try following command:

Code: Select all

Command: cmd.exe /c Full\Path\To\Bat\File.bat
Parameters: "%WL"
Maybe cmd will execute batch itself insted of calling DOSBox, I can't check it since I've never associated DOSBox with batch files.
User avatar
tuska
Power Member
Power Member
Posts: 3760
Joined: 2007-05-21, 12:17 UTC

Post by *tuska »

I have tried as suggested and additionally with ...\File.cmd.
It works in both cases but the DOS-Box remains and spacebar must be pushed to force disappearance of this window.
Thanks anyway!
Gruß,
Karl
hooly
Junior Member
Junior Member
Posts: 15
Joined: 2008-05-26, 06:53 UTC

Post by *hooly »

fwiw i managed to cobble together an AHK script to do what i wanted, thought it might be of use to others so here it is:

Code: Select all

; Touch (default) ala UNIX
; script is designed to be called from TotalCommander where the files and/or
; folders to be Touch-ed are sent in as a (temporary) list file .. script
; assumes that each entry in the list is a full path, IOW %L is used in
; TotalCommander's "Parameters" box.

Loop, Read, %1%
{
    nextFileOrDir = %A_LoopReadLine%
    FileGetAttrib, nextAttributes, %nextFileOrDir%
    IfInString, nextAttributes, D
    {
        ; folder (directory) entries in the list
        ; come to us with a trailing slash, need to
        ; trim that before we proceed.
        
        StringTrimRight, nextFileOrDir, nextFileOrDir, 1
    }
    
    FileSetTime , A_Now, %nextFileOrDir%, M
}
no claims to originality or wonderfulness are made or implied: i borrowed freely from others and am a noobie AHK scripter so it is what it is. improvements and/or recommendations are most welcome.
bobputnam
Junior Member
Junior Member
Posts: 77
Joined: 2003-05-26, 12:31 UTC
Location: Connecticut, USA

Post by *bobputnam »

With the batch file, add a final line:
exit

will close out the "DOS" window.
Bob P
3-User License 71012
damjang
Senior Member
Senior Member
Posts: 215
Joined: 2003-10-09, 15:58 UTC
Contact:

Post by *damjang »

bobputnam wrote:With the batch file, add a final line:
exit

will close out the "DOS" window.
I think that the cause of dos-box stay open is the "pause" command. Try to remove the line with "pause" and that should work
User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom »

hooly wrote:fwiw i managed to cobble together an AHK script to do what i wanted, thought it might be of use to others so here it is:
...
no claims to originality or wonderfulness are made or implied: i borrowed freely from others and am a noobie AHK scripter so it is what it is. improvements and/or recommendations are most welcome.
Try this:

Code: Select all

#NoEnv
curTime:=A_Now
Loop, Read, %1%
	FileSetTime, %curTime%, % (SubStr(A_LoopReadLIne,0) == "" ? SubStr(A_LoopReadLine,1,-1) : A_LoopReadLine), M
1) All files will get the same time stamp, instead of a continuingly changing A_Now. If that is not desired. Remove the curTime assignment (line 2). And replace %curTime% with: %A_Now% (line 4).

No variable assignments during the loop, we just use A_LoopReadLine. Also no need to check if it is a directory and store the result, just check if the last character of A_LoopReadLine is equal to "", and if so, strip it with SubStr.
Shorthand if/else above.
---> (IF SOMETHING) ? THEN DO THIS : ELSE DO THIS

Note: You should always add #NoEnv to scripts. As well it wouldn't hurt to add these three, which are the default lines AHK will generate if you use it to launch a non-existant script:

Code: Select all

#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
hooly
Junior Member
Junior Member
Posts: 15
Joined: 2008-05-26, 06:53 UTC

Post by *hooly »

@Balderstrom: thank you for the tips and pointers on the script, much appreciated.
Post Reply