Dates and Filenames??? 
Author Message
 Dates and Filenames???

Hello world,

I hope someone can help me!!

What I need to do is to be able to rename a file based on the current
date....ie: if todays date is 15/5/96 I need to rename a file to be
960515.txt

Can anyone help me do this in BP7.0?????

ANY help would be great...

Thanks in advance....

Dean Harry



Wed, 18 Jun 1902 08:00:00 GMT  
 Dates and Filenames???

Quote:
> What I need to do is to be able to rename a file based on the current
> date....ie: if todays date is 15/5/96 I need to rename a file to be
> 960515.txt
> Can anyone help me do this in BP7.0?????

   It's done with a combination of the following:

  - GetDate (obtain system date)
  - Str (convert numeric data to string)
  - the string concanenation operator (+)
  - Assign
  - Rename

   I won't post the code, but if you look these things up, you'll see how
they're used.  Note that date components < 10 must be filled with '0's,
and you should also check to see that the target file name isn't already
being used.



Wed, 18 Jun 1902 08:00:00 GMT  
 Dates and Filenames???

Quote:

>What I need to do is to be able to rename a file based on the current
>date....ie: if todays date is 15/5/96 I need to rename a file to be
>960515.txt

>Can anyone help me do this in BP7.0?????

Try the GetDate procedure from the Dos unit, the Str procedure, and the
Rename procedure.

Ron



Wed, 18 Jun 1902 08:00:00 GMT  
 Dates and Filenames???


Wed, 18 Jun 1902 08:00:00 GMT  
 Dates and Filenames???

Archive-name: tpdate01.pas

Quote:

> What I need to do is to be able to rename a file based on the current
> date....ie: if todays date is 15/5/96 I need to rename a file to be
> 960515.txt

stripping out code from my GENERICF.PAS :

function rightjustify(s: string; width: integer; c: char): string;

var
  result: string;

begin
  result := s;

  while length(result)<width do
    result := c+result;

  rightjustify := result;
end;

function wordtozstring(w: word; width: integer): string;

var
  result: string;

begin
  str(w,result);

  wordtozstring := rightjustify(result,width,'0');
end;

function ymdtostring(year, month, day: word): string;

begin
  ymdtostring := wordtozstring(year,2) {+'-'} +
   wordtozstring(month,2) {+'-'} +wordtozstring(day,2);
end;

function currentdatestring: string;

var
  year, month, day, dayofweek: word;

begin
  getdate(year,month,day,dayofweek);
  currentdatestring := ymdtostring(year,month,day);
end;

then you would rename your old file to "currentdatestring+'.txt'"

from that package (part of rnr*.zip, ftp- and http-able), see also
function dateformatted(y,m,d: word; dateformat: string): string;
which does some fairly cool things -- allowing

mmm dd, yy    => Jun 7, 96
www, yy-mm-dd => Fri, 96-06-07

and similar things.  (as a bonus, it calculates the day of week for
any date (those past 1980, anyway)).
--



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Long FileName - Short Filename conversion

2. Unknown filenames/unit filenames

3. Using b.c. Dates In Date fields

4. Select form Date 1 to Date 2

5. Date only or Date and Time ?

6. UNIT: Returns verbose date info - date.pas (0/1)

7. UNIT: Returns verbose date info - date.pas (1/1)

8. Getting file *creation* date, not modified date

9. Getting Date/Time from LAN Machine and Setting Date/Time on Client

10. Using the Date value for assigning Today's date to a field

11. If Exist(filename) alway returns true on new faster computer

12. Long filenames in DOS mode

 

 
Powered by phpBB® Forum Software