2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
5 Desc: SetDate CLI command
9 /*************************************************************************
17 SetDate (file | pattern) [(weekday)] [(date)] [(time)] [ALL]
21 FILE/A,WEEKDAY,DATE,TIME,ALL/S
29 Changes the date and time of the creation or last change of a file or
30 directory. With option ALL, it also changes the date and time of all
31 files and subdirectories within directories matching the specified
32 pattern. If either the date or time is unspecified, the current date
37 FILE -- File (or pattern) to change the date of.
39 WEEKDAY -- Specification of the day of the date. This is locale
40 sensitive, and you may use standard keywords such as
41 'Tomorrow' and 'Yesterday' (in the language used, of
44 DATE -- A date in the format DD-MMM-YY.
45 MMM is either the number or the first 3 letters of the
48 TIME -- Time string in the format HH:MM:SS or HH:MM.
50 ALL -- Recurse through subdirectories.
54 Standard DOS return codes
62 Sets the date for all files and directories in the current directory
63 and its subdirectories to the current date.
75 *************************************************************************/
78 #include <proto/exec.h>
79 #include <dos/datetime.h>
80 #include <proto/dos.h>
81 #include <dos/rdargs.h>
82 #include <dos/dosasl.h>
84 #define MAX_PATH_LEN 512
86 const TEXT version
[] = "$VER: SetDate 1.1 (3.4.2014)\n";
88 enum { ARG_FILE
= 0, ARG_WEEKDAY
, ARG_DATE
, ARG_TIME
, ARG_ALL
};
94 struct AnchorPath
*aPath
;
96 IPTR args
[5] = { (IPTR
)NULL
, (IPTR
)NULL
, (IPTR
)NULL
, (IPTR
)NULL
, (IPTR
)FALSE
};
100 LONG retval
= RETURN_OK
;
101 BOOL timeError
= FALSE
; /* Error in time/date specification? */
103 rda
= ReadArgs("FILE/A,WEEKDAY,DATE,TIME,ALL/S", args
, NULL
);
107 PrintFault(IoErr(), "SetDate");
111 /* Use the current time as default (if no DATE, TIME or WEEKDAY is
113 DateStamp(&dt
.dat_Stamp
);
115 dt
.dat_Flags
= DTF_FUTURE
;
116 dt
.dat_Format
= FORMAT_DOS
;
117 dt
.dat_StrDate
= (TEXT
*)args
[ARG_DATE
];
118 dt
.dat_StrTime
= (TEXT
*)args
[ARG_TIME
];
120 /* Change the defaults according to the user's specifications */
123 dt
.dat_StrDate
= (TEXT
*)args
[ARG_WEEKDAY
];
137 PutStr("SetDate: Illegal DATE or TIME string\n");
141 aPath
= AllocVec(sizeof(struct AnchorPath
) + MAX_PATH_LEN
,
142 MEMF_ANY
| MEMF_CLEAR
);
146 aPath
->ap_Flags
= (BOOL
)args
[ARG_ALL
] ? (APF_DODIR
| APF_DOWILD
) : APF_DOWILD
;
147 aPath
->ap_BreakBits
= SIGBREAKF_CTRL_C
;
148 aPath
->ap_Strlen
= MAX_PATH_LEN
;
150 /* Save the current dir */
151 oldCurDir
= CurrentDir(BNULL
);
152 CurrentDir(oldCurDir
);
154 error
= MatchFirst((STRPTR
)args
[ARG_FILE
], aPath
);
158 CurrentDir(aPath
->ap_Current
->an_Lock
);
160 //VPrintf("%s\n", (IPTR *)&aPath->ap_Info.fib_FileName);
161 if ( ((&aPath
->ap_Info
)->fib_DirEntryType
>= 0)
162 && !(aPath
->ap_Flags
& APF_DIDDIR
)
163 && ((BOOL
)args
[ARG_ALL
]))
165 aPath
->ap_Flags
|= APF_DODIR
;
167 SetFileDate(aPath
->ap_Info
.fib_FileName
, &dt
.dat_Stamp
);
169 error
= MatchNext(aPath
);
174 /* Restore the current dir */
175 CurrentDir(oldCurDir
);
182 retval
= RETURN_FAIL
;
185 if(error
!= ERROR_NO_MORE_ENTRIES
)
187 if(error
== ERROR_BREAK
)
189 retval
= RETURN_WARN
;
193 retval
= RETURN_FAIL
;
196 PrintFault(error
, "SetDate");