2 Copyright © 1995-2008, 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.
67 ALL flag does not work.
75 *************************************************************************/
78 #include <dos/datetime.h>
79 #include <proto/dos.h>
80 #include <dos/rdargs.h>
81 #include <dos/dosasl.h>
83 enum { ARG_FILE
= 0, ARG_WEEKDAY
, ARG_DATE
, ARG_TIME
, ARG_ALL
};
89 struct AnchorPath aPath
;
91 IPTR args
[5] = { NULL
, NULL
, NULL
, NULL
, FALSE
};
95 LONG retval
= RETURN_OK
;
96 BOOL timeError
= FALSE
; /* Error in time/date specification? */
98 rda
= ReadArgs("FILE/A,WEEKDAY,DATE,TIME,ALL/S", args
, NULL
);
102 PrintFault(IoErr(), "SetDate");
106 /* Use the current time as default (if no DATE, TIME or WEEKDAY is
108 DateStamp(&dt
.dat_Stamp
);
110 dt
.dat_Flags
= DTF_FUTURE
;
111 dt
.dat_Format
= FORMAT_DOS
;
112 dt
.dat_StrDate
= (TEXT
*)args
[ARG_DATE
];
113 dt
.dat_StrTime
= (TEXT
*)args
[ARG_TIME
];
115 /* Change the defaults according to the user's specifications */
118 dt
.dat_StrDate
= (TEXT
*)args
[ARG_WEEKDAY
];
128 PutStr("SetDate: Illegal DATE or TIME string\n");
133 aPath
.ap_Flags
= (BOOL
)args
[ARG_ALL
] ? APF_DOWILD
: 0;
134 aPath
.ap_BreakBits
= SIGBREAKF_CTRL_C
;
137 /* Save the current dir */
138 oldCurDir
= CurrentDir(NULL
);
139 CurrentDir(oldCurDir
);
141 error
= MatchFirst((STRPTR
)args
[ARG_FILE
], &aPath
);
145 CurrentDir(aPath
.ap_Current
->an_Lock
);
147 // VPrintf("%s", (IPTR *)&aPath.ap_Info.fib_FileName);
149 SetFileDate(aPath
.ap_Info
.fib_FileName
, &dt
.dat_Stamp
);
151 error
= MatchNext(&aPath
);
156 /* Restore the current dir */
157 CurrentDir(oldCurDir
);
161 if(error
!= ERROR_NO_MORE_ENTRIES
)
163 if(error
== ERROR_BREAK
)
164 retval
= RETURN_WARN
;
166 retval
= RETURN_FAIL
;
168 PrintFault(IoErr(), "SetDate");