Date into new file name 
Author Message
 Date into new file name

I can't figure out how I would put the year,day, and month into
new_name. It would rename bookmarks.html to 01-12_03.html

; today.asm
; Written by: John A Lyons                                              
   ;
; Page      : http://www.*-*-*.com/ ;                    
   ;
; Date      : 13 December 1997                                          

cseg segment
assume cs:cseg, ds:cseg
org 100H
jumps

begin:

                push cs
                pop ds
                mov ah,4
                int 1ah

                mov al,cl
                xor ah,ah
                mov bl,10h
                div bl
                add ax,3030h
                mov cs:[year],al
                mov cs:[year+1],ah

                mov al,dh
                xor ah,ah
                div bl
                add ax,3030h
                mov cs:[month],al
                mov cs:[month+1],ah

                mov al,dl
                xor ah,ah
                div bl
                add ax,3030h
                mov cs:[day],al
                mov cs:[day+1],ah

                mov dl, [month]
                mov ah,2
                int 21h
                mov dl, [month+1]
                mov ah,2
                int 21h
                mov dl,'_'
                mov ah,2
                int 21h

                mov dl, [day]
                mov ah,2
                int 21h
                mov dl, [day+1]
                mov ah,2
                int 21h
                mov dl,'_'
                mov ah,2
                int 21h

                mov dl, [year]
                mov ah,2
                int 21h
                mov dl, [year+1]
                mov ah,2
                int 21h
open0:
                mov ah,4ch
                int 21h

             mov          dx,offset file_name + 2  ; old file name
             mov          ax,seg new_name       ; new file name
             mov          es,ax
             mov          di,offset new_name    ; new file name
             mov          ah,56h
             int          21h

  day           db '00'
  month         db '00'
  year          db '00'  
  file_name     db   'bookmarks.html',0
  new_name      db   '??????.html',0

cseg ends
end begin



Fri, 01 Jul 2005 07:51:33 GMT  
 Date into new file name



Quote:

> I can't figure out how I would put the year,day, and month into
> new_name. It would rename bookmarks.html to 01-12_03.html

Remove the code starting from "mov dl, [month]" upto the label "open0:", and
look again. Everything you need is in there, it just does not get put in the
"right" place.

Regards,
  Rudy Wieser

Quote:
> ; today.asm
> ; Written by: John A Lyons
>    ;
> ; Page      : http://www.megablast.8k.com/asm.html
>    ;
> ; Date      : 13 December 1997

> cseg segment
> assume cs:cseg, ds:cseg
> org 100H
> jumps

> begin:

>                 push cs
>                 pop ds
>                 mov ah,4
>                 int 1ah

>                 mov al,cl
>                 xor ah,ah
>                 mov bl,10h
>                 div bl
>                 add ax,3030h
>                 mov cs:[year],al
>                 mov cs:[year+1],ah

>                 mov al,dh
>                 xor ah,ah
>                 div bl
>                 add ax,3030h
>                 mov cs:[month],al
>                 mov cs:[month+1],ah

>                 mov al,dl
>                 xor ah,ah
>                 div bl
>                 add ax,3030h
>                 mov cs:[day],al
>                 mov cs:[day+1],ah

>                 mov dl, [month]
>                 mov ah,2
>                 int 21h
>                 mov dl, [month+1]
>                 mov ah,2
>                 int 21h
>                 mov dl,'_'
>                 mov ah,2
>                 int 21h

>                 mov dl, [day]
>                 mov ah,2
>                 int 21h
>                 mov dl, [day+1]
>                 mov ah,2
>                 int 21h
>                 mov dl,'_'
>                 mov ah,2
>                 int 21h

>                 mov dl, [year]
>                 mov ah,2
>                 int 21h
>                 mov dl, [year+1]
>                 mov ah,2
>                 int 21h
> open0:
>                 mov ah,4ch
>                 int 21h

>              mov          dx,offset file_name + 2  ; old file name
>              mov          ax,seg new_name       ; new file name
>              mov          es,ax
>              mov          di,offset new_name    ; new file name
>              mov          ah,56h
>              int          21h

>   day           db '00'
>   month         db '00'
>   year          db '00'
>   file_name     db   'bookmarks.html',0
>   new_name      db   '??????.html',0

> cseg ends
> end begin



Fri, 01 Jul 2005 18:10:44 GMT  
 Date into new file name

Quote:
>Remove the code starting from "mov dl, [month]" upto the label "open0:",
and
>look again. Everything you need is in there, it just does not get put in
the
>"right" place.

It outputs to the screen OK, but the rename still isn't working correctly.
I don't know if it's because of the 4 place file extension or something else.
I tried the extended file rename with no luck either. I am writing this program
for a continual need asked in the batch file and other newsgroups. People
are wanting a  batch file to rename a file based on the current date. Their
best effort uses gawk, debug, and batch file commands. Kind of like using
a pocket knife to make a bookshelf, it can be done, but it'll look like crap.
Once I get the renaming working, I will add a command line prompt that will
let the user change what the initial filename is. Thanks.

 ; today.asm
 ; Written by: John A Lyons

model small
stack 200h

data

    day           db '00'
    month         db '00'
    year          db '00'
    file_name     db   'bookmarks.html',0
    new_name      db   128 dup(?)

code
 begin:

                 push cs
                 pop ds
                 mov ah,4
                 int 1ah

                 mov al,cl
                 xor ah,ah
                 mov bl,10h
                 div bl
                 add ax,3030h
                 mov [year],al
                 mov [year+1],ah

                 mov al,dh
                 xor ah,ah
                 div bl
                 add ax,3030h
                  mov [month],al
                  mov [month+1],ah

                  mov al,dl
                  xor ah,ah
                  div bl
                  add ax,3030h
                  mov [day],al
                  mov [day+1],ah

                  mov dl, [month]
                  mov ah,2
                  int 21h
                  mov dl, [month+1]
                  mov ah,2
                  int 21h
                  mov dl,'_'
                  mov ah,2
                  int 21h

                  mov dl, [day]
                  mov ah,2
                  int 21h
                  mov dl, [day+1]
                  mov ah,2
                  int 21h
                  mov dl,'_'
                  mov ah,2
                  int 21h

                  mov dl, [year]
                  mov ah,2
                  int 21h
                  mov dl, [year+1]
                  mov ah,2
                  int 21h

        mov     al, [day]              
        mov     byte ptr new_name, al
        mov     al, [day + 1]
        mov     byte ptr new_name+1,al
        mov     al,00                    ; make it null terminated
        mov     byte ptr new_name+2,al

               mov          dx,offset file_name + 2  ; old file name
               mov          ax,seg new_name       ; new file name
               mov          es,ax
               mov          di,offset new_name    ; new file name
               mov          ah,56h
               int          21h

  open0:
                  mov ah,4ch
                  int 21h

end begin



Fri, 01 Jul 2005 21:11:51 GMT  
 Date into new file name

Quote:

> I am writing this program
> for a continual need asked in the batch file and other newsgroups. People
> are wanting a  batch file to rename a file based on the current date. Their
> best effort uses gawk, debug, and batch file commands. Kind of like using
> a pocket knife to make a bookshelf, it can be done, but it'll look like crap.

In W2k/XP you can do this using the %date% variable. In DOS/Win9x
use the rename command and use your program only to get the date.
But I would not use mmddyy but yymmdd. Here an example:





dat.com >dat.bat
call dat.bat
echo ren bookmark.html %date%.html
del dat.com
del dat.bat
set date=

The source:

; write set date=yymmdd >stdout


        move.b  #$2a,m0         ; get date function
        trap    #$21            ; call dos
        move.w  r2,r0           ; year
        divu.b  c100,m0|r0      ; last 2 digits -> m0
        lsr.w   #8,r0           ; last 2 digits -> r0
        move.w  #buf1,r3        ; adr of write buffer
        bsr.w   _500            ; output in write buffer
        move.b  m1,r0           ; month
        bsr.w   _500            ; output in write buffer
        move.b  r1,r0           ; day
        bsr.w   _500            ; output in write buffer

        move.b  #$40,m0         ; write function
        move.w  #buf,r1         ; adr of write buffer
        move.w  #9+6,r2         ; write 6 char: yymmdd
        move.w  #1,r3           ; stdout
        trap    #$21            ; call dos
        rts.w

_500:   divu.b  c10,m0|r0       ; r0=high m0=low digit
        add.w   #'00',r0        ; convert to ascii
        move.w  r0,(r3.w)       ; copy in write buffer
        inc.w   r3              ; inc write pointer
        inc.w   r3              ; inc write pointer
        eor.w   r0,r0           ; clear r0
        rts.w

c100:   dc.b    100             ; constant 100
c10:    dc.b    10              ; constant  10

buf:    dc.b    'set date='
buf1:



Fri, 01 Jul 2005 21:36:32 GMT  
 Date into new file name


Quote:

> > Remove the code starting from "mov dl, [month]" upto
> > the label "open0:", and look again. Everything you need
> > is in there, it just does not get put in the "right" place.

> It outputs to the screen OK, but the rename still isn't working correctly.
> I don't know if it's because of the 4 place file extension or something
else.
> I tried the extended file rename with no luck either. I am writing this
program
> for a continual need asked in the batch file and other newsgroups. People
> are wanting a  batch file to rename a file based on the current date.
Their
> best effort uses gawk, debug, and batch file commands. Kind of like using
> a pocket knife to make a bookshelf, it can be done, but it'll look like
crap.
> Once I get the renaming working, I will add a command line prompt that
will
> let the user change what the initial filename is. Thanks.

You're welcome.

Now let's take a look at your program :

- Show quoted text -

Quote:
>  ; today.asm
>  ; Written by: John A Lyons

> model small
> stack 200h

> data

>     day           db '00'
>     month         db '00'
>     year          db '00'
>     file_name     db   'bookmarks.html',0
>     new_name      db   128 dup(?)

> code
>  begin:

>                  push cs
>                  pop ds
>                  mov ah,4
>                  int 1ah

>                  mov al,cl
>                  xor ah,ah
>                  mov bl,10h
>                  div bl
>                  add ax,3030h
>                  mov [year],al
>                  mov [year+1],ah

>                  mov al,dh
>                  xor ah,ah
>                  div bl
>                  add ax,3030h
>                   mov [month],al
>                   mov [month+1],ah

>                   mov al,dl
>                   xor ah,ah
>                   div bl
>                   add ax,3030h
>                   mov [day],al
>                   mov [day+1],ah

The below part is Screen-output only.  You don't need it for the renaming.

- Show quoted text -

Quote:
>                   mov dl, [month]
>                   mov ah,2
>                   int 21h
>                   mov dl, [month+1]
>                   mov ah,2
>                   int 21h
>                   mov dl,'_'
>                   mov ah,2
>                   int 21h

>                   mov dl, [day]
>                   mov ah,2
>                   int 21h
>                   mov dl, [day+1]
>                   mov ah,2
>                   int 21h
>                   mov dl,'_'
>                   mov ah,2
>                   int 21h

>                   mov dl, [year]
>                   mov ah,2
>                   int 21h
>                   mov dl, [year+1]
>                   mov ah,2
>                   int 21h

Create a name consisting outof the current Day only.  It's O.K.

Quote:
>         mov     al, [day]
>         mov     byte ptr new_name, al
>         mov     al, [day + 1]
>         mov     byte ptr new_name+1,al
>         mov     al,00                    ; make it null terminated
>         mov     byte ptr new_name+2,al
>                mov          dx,offset file_name + 2  ; old file name

You've got a problem in the above line.  Can you spot it ?   (Wat is DX
pointing at ?  Are you sure ?)

Quote:
>                mov          ax,seg new_name       ; new file name
>                mov          es,ax

Don't do this.  You're do not want to generate an EXE-type file, so
Segment-designators like these ( "seg new_name" ) can't be used.  Just use a
"push ds", "pop es" pair or a "mov ax,ds" , "mov es,ax" pair.

Quote:
>                mov          di,offset new_name    ; new file name
>                mov          ah,56h
>                int          21h

>   open0:
>                   mov ah,4ch
>                   int 21h

> end begin

Regards,
  Rudy Wieser


Fri, 01 Jul 2005 21:36:19 GMT  
 Date into new file name

Quote:
>>         mov     byte ptr new_name+2,al

>>                mov          dx,offset file_name + 2  ; old file name

>You've got a problem in the above line.  Can you spot it ?   (Wat is DX
>pointing at ?  Are you sure ?)

The filename +2 came from other code that worked.

Quote:
>>                mov          ax,seg new_name       ; new file name
>>                mov          es,ax

>Don't do this.  You're do not want to generate an EXE-type file, so
>Segment-designators like these ( "seg new_name" ) can't be used.  Just use
a
>"push ds", "pop es" pair or a "mov ax,ds" , "mov es,ax" pair.

>>                mov          di,offset new_name    ; new file name
>>                mov          ah,56h
>>                int          21h

>>   open0:
>>                   mov ah,4ch
>>                   int 21h

I tried this with no change.

               mov       dx,offset file_name   ; old file name
               push      ds
               pop       es    
               mov       di,offset new_name    ; new file name
               mov       ah,56h
               int       21h



Fri, 01 Jul 2005 22:18:57 GMT  
 Date into new file name

 > It outputs to the screen OK, but the rename still isn't working
 > correctly. I don't know if it's because of the 4 place file extension
 > or something else.

A 4-char extension will probably{*filter*}up the int 21h/56h function.

 > I tried the extended file rename with no luck
 > either.

<consults Ralf> Oh yeah! int 21h/7156h! Yeah that seems to work!

 > I am writing this program for a continual need asked in the
 > batch file and other newsgroups. People are wanting a  batch file to
 > rename a file based on the current date. Their best effort uses gawk,
 > debug, and batch file commands.

They still re-inventing *that* wheel? :)

 > Kind of like using a pocket knife to
 > make a bookshelf, it can be done, but it'll look like crap.

Depends on how good you are with the pocket knife, dunnit? Some of those
batch-file programmers were pretty clever, when I was following it. (I
think "echo Hello, World!" still wins!)

Here's how I'd do it. I just stuck the LFN rename function in there to
try - it needs better error handling (returns 7100h in ax if "function
not supported, which would return errorlevel 0 to the caller). I just
pass all errors to the caller - assuming it's a batch file. Really
should provide it's own "usage" message at least, I guess...

Best,
Frank

; nasm -f bin -o ren2date.com ren2date.asm

org 100h

section .text

wind_me:
     mov ah, 4          ; get date
     int 1Ah            ; call AT(!) bios
     jc wind_me         ; clock stopped or updating
                        ; (if stopped, we wait :)
     mov di, newname    ; that's "offset newname" to you :)

     mov al, ch         ; this does 4 digit year
     call twodigits     ; convert bcd to ascii
     mov al, cl
     call twodigits

     mov al, dh         ; month
     call twodigits
     mov al, dl         ; day
     call twodigits

     mov si, 80h        ; parse command-line
     lodsb
     or al, al          ; if any
     jnz strip
     dec al             ; return an errorlevel
     jmp short exit     ; (or "usage")
strip:
     mov dx, si         ; set up dx for the "rename" call
     lodsb
     cmp al, ' '        ; strip leading spaces
     jz strip
     cmp al, '/'        ; it's possible...
     jz strip
     dec si             ; back up and get it again
getcl:                 ; (could be CR or '.')
     lodsb
     cmp al, 0Dh
     jz gotcl
     cmp al, '.'        ; ignore the first part
     jnz getcl
getext:
     stosb              ; copy the extension to "newname"
     lodsb
     cmp al, 0Dh
     jnz getext
gotcl:
     xor al, al
     stosb              ; terminate newname
     mov [si - 1], al   ; terminate oldname (overwrite CR)

     mov di, newname
;    mov ah, 56h
     mov ax, 7156h
     int 21h            ; rename
exit:                  ; pass any error to caller
     mov ah, 4Ch
     int 21h
;----------------------------

;-----------
; convert bcd in al to two ascii digits
; and stuff 'em in es:di
;-----------
twodigits:
     aam 16
     add ax, 3030h
     xchg ah, al
     stosw
     ret
;--------------

section .bss
     newname resb 80h
;----------------



Sat, 02 Jul 2005 02:08:55 GMT  
 Date into new file name

Quote:
><consults Ralf> Oh yeah! int 21h/7156h! Yeah that seems to work!
> > I am writing this program for a continual need asked in the

I modified but it still doesn't work.

I used renam c:\bookmarks.html.

;  renam.asm  

model   small
stack   200h    ; 512 byte stack

data

newname db      128 dup(?)

code

start:                      

         mov      ds,ax
wind_me:
     mov ah, 4          ; get date
     int 1Ah            ; call AT(!) bios
     jc wind_me         ; clock stopped or updating
                        ; (if stopped, we wait :)
     mov di, offset newname    ; that's "offset newname" to you :)

     mov al, ch         ; this does 4 digit year
     call twodigits     ; convert bcd to ascii
     mov al, cl
     call twodigits

     mov al, dh         ; month
     call twodigits
     mov al, dl         ; day
     call twodigits

     mov si, 80h        ; parse command-line
     lodsb
     or al, al          ; if any
     jnz strip
     dec al             ; return an errorlevel
     jmp short exit     ; (or "usage")
strip:
     mov dx, si         ; set up dx for the "rename" call
     lodsb
     cmp al, ' '        ; strip leading spaces
     jz strip
     cmp al, '/'        ; it's possible...
     jz strip
     dec si             ; back up and get it again
getcl:                 ; (could be CR or '.')
     lodsb
     cmp al, 0Dh
     jz gotcl
     cmp al, '.'        ; ignore the first part
     jnz getcl
getext:
     stosb              ; copy the extension to "newname"
     lodsb
     cmp al, 0Dh
     jnz getext
gotcl:
     xor al, al
     stosb              ; terminate newname
     mov [si - 1], al   ; terminate oldname (overwrite CR)

     mov di, offset newname
;    mov ah, 56h
     mov ax, 7156h
     int 21h            ; rename

;-----------
; convert bcd in al to two ascii digits
; and stuff 'em in es:di
;-----------
twodigits:
     aam 16
     add ax, 3030h
     xchg ah, al
     stosw
     ret

exit:            
         mov          ax,4c00h
         int          21h

end     start



Sat, 02 Jul 2005 02:33:07 GMT  
 Date into new file name

Quote:

>><consults Ralf> Oh yeah! int 21h/7156h! Yeah that seems to work!

>>>I am writing this program for a continual need asked in the

> I modified but it still doesn't work.

> I used renam c:\bookmarks.html.

> ;  renam.asm  

> model   small
> stack   200h    ; 512 byte stack

Oops! I thought you were making a ".com" file. What I posted won't work
as an ".exe" because of the different way that dos loads 'em. Dos loads
a .com file with cs=ds=es=PSP. An .exe has data and PSP (the command
tail) in different segments, so the "lodsb"/"stosb" won't work without
more juggling of segment registers. I might want to do it a bit
differently as an .exe. But y'know, I think that - just by chance - that
particular mess would work if you just changed the startup code to:

mov ax, data
mov es, ax

Leave ds alone - it doesn't need to point to data here... (does it?)
ds=PSP=command-tail (oldname), es=data=ascii date (newname)... That
should be correct, all the way through... That's untested! It would be
unusual code, but I think it would work... I may be missing something...

Later,
Frank



Sat, 02 Jul 2005 03:35:40 GMT  
 Date into new file name

I found this code for another compiler. The supplied com file works but not
my Tasm version which is below it.

; The program renames a file with a long name
; The path must also be specified
; Works ONLY under Windows or perhaps Protected Mode,
; not known yet.

        org     100h
start:
        mov     ax,7156h        ; rename file
        lea     dx,Name         ; old name
        lea     di,Newname      ; sets the new name
        int     21h

        ret

Name    db      'c:\Test.txt',0         ; file name and path
Newname db      'c:\Rename.txt',0       ; new file name and path

end

; lfnren.asm Tasm version
;
model    small
stack    200h

data

old      db        'c:\test.txt',0     ; file name and path
newname   db        'c:\rename.txt',0   ; new file name and path

code

start:
          mov       ax,7156h    ; rename file
          mov       dx, old     ; old name
          mov       di, newname ; sets the new name
          int       21h
          mov       ax,4c00h
          int       21h

end   start



Sat, 02 Jul 2005 04:02:55 GMT  
 Date into new file name

Quote:

> I found this code for another compiler. The supplied com file works but not
> my Tasm version which is below it.

[snip working (.com) version]

Quote:
> ; lfnren.asm Tasm version
> ;
> model    small
> stack    200h

> data

> old      db        'c:\test.txt',0     ; file name and path
> newname   db        'c:\rename.txt',0   ; new file name and path

> code

> start:

mov ax, data
mov ds, ax

Quote:
>           mov          ax,7156h    ; rename file
>           mov       dx, old     ; old name
>           mov       di, newname ; sets the new name

"offset" for Tasm? (or "lea...")

Quote:
>      int       21h
>           mov       ax,4c00h
>           int       21h

> end   start

There's a "segreg problem" in the code you posted on clax, too. You do
"push cs"/"pop ds" - but your data isn't *in* the code segment. And the
command-line (when you get to it) is in still another segment (ds and es
point to PSP on startup, or get it with int 21h/62h). Really, those
disgusting old obsolete .com files are easier!

Best,
Frank



Sat, 02 Jul 2005 05:41:24 GMT  
 
 [ 23 post ]  Go to page: [1] [2]

 Relevant Pages 

1. How can I know the .EXE file name, file date, file size

2. DOS File Lookup - just the file name, not the path AND file name

3. Windows native file dialog default sort is by date instead of name

4. ftp a file by date and name match

5. Developing date file names

6. How to copy data between 2 dates in new file

7. Long file names (new library available for download)

8. Create Time / date or Modified Time / date of a txt file

9. CW2.003 File copy changes the date.....need a way to copy w/o date change

10. mkdir same name as file name

11. file name vs. real name

12. get file size and file date

 

 
Powered by phpBB® Forum Software