Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: What Does This Mean?  (Read 3327 times)

0 Members and 1 Guest are viewing this topic.

JanSco

  • Guest
What Does This Mean?
« on: February 21, 2007, 12:35:53 PM »
I got some code off the internet which appends the current date to the end of a filename and changes the '/' to a '-'.  It's exactly what I needed.  However, I would like to understand what the code means (starting with the first %).

copy MainFile.TXT MainFile%date:~4,2%-%date:~7,2%-%date:~10%.txt
                                                              
                                                    

dworley



    Beginner

    Thanked: 1
    Re: What Does This Mean?
    « Reply #1 on: February 21, 2007, 04:23:01 PM »
    when there is something written inside %%s (like %joe%) it is referring to the variable stated inside the %%s (like joe)...

    So, when it refers to %date....%, it is referring to the integrated variable "date" (which, as you may guess is the current date).

    The other bits within the %%s are formatting items. Initially, %date% is "day mm/dd/yyy" (like 'wed 02/22/2002)... which doesn't work well in a name because of the slashes. So it must be parsed out...

    for example %date:~4,2% means to take %date% and only return the parts after the 4th character. The 2 refers to the length of the string to return. So basically, this tells it to return characters 4-6 of the %date% string.

    It does this three times to give the date in the filename.

    I hope this makes sense...

    -darryl
    Have you forgotten?