Results 1 to 7 of 7
  1. #1
    4 Star Lounger
    Join Date
    Jul 2006
    Posts
    531
    Thanks
    0
    Thanked 0 Times in 0 Posts

    syntax to copy filename to another filename (latest)

    I have a batch file and within the batch file l would like to know the syntax to copy a file so that it is renamed with the date at the end.
    i.e bluesky.rfs to be copied to bluesky 05/08/08.xls

  2. #2
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: syntax to copy filename to another filename (latest)

    <P ID="edit" class=small>(Edited by JohnBF on 05-Sep-08 14:53. corrected pasting errors.)</P>Not sure this is the Forum for this question, but try this:

    ::copywithdate.bat
    ::syntax: copywithdate filename.ext
    @echo off
    %comspec% /e:2048/c for %%v in (1 2) do prompt set TempDate$q$d$_ | find/v "$" >{t}.bat
    for %%v in (call del) do %%v {t}.bat
    set TempFile=%~n1
    set TempDate=%TempDate:/=-%
    set TempDate=%TempDate:Sun =%
    set TempDate=%TempDate:Mon =%
    set TempDate=%TempDate:Tue =%
    set TempDate=%TempDate:Wed =%
    set TempDate=%TempDate:Thu =%
    set TempDate=%TempDate:Fri =%
    set TempDate=%TempDate:Sat =%
    copy %1 %TempFile%%TempDate%.xls

    Tom Lavedas provided the date extraction - the first two lines. The removals of the day name string could probably be done better, but paid work beckons.
    -John ... I float in liquid gardens
    UTC -7ąDS

  3. #3
    4 Star Lounger
    Join Date
    Jul 2006
    Posts
    531
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: syntax to copy filename to another filename (latest)

    I am unclear how l would incorporate this coding into a batch file containing this coding:, would it work?


    echo off
    start excel.exe "G:AccountsBlueSky InformationBlue Sky RFS's.xls"

  4. #4
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: syntax to copy filename to another filename (latest)

    The above is your entire batch file? You would put all the batch code I posted before the "start" line and eliminate the duplicate echo off (there are some limitations). But if all your batch code does is start Excel with a specific file, why don't you do the rename and date add in VBA code instanced by Excel?
    -John ... I float in liquid gardens
    UTC -7ąDS

  5. #5
    4 Star Lounger
    Join Date
    Jul 2006
    Posts
    531
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: syntax to copy filename to another filename (latest)

    I am not to sure what you mean, please can explain in details what you mean by:

    why don't you do the rename and date add in VBA code instanced by Excel?

  6. #6
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: syntax to copy filename to another filename (latest)

    I mean that if your purpose is to open a renamed file in Excel, it would be better to rename and open the file through Excel VBA.
    -John ... I float in liquid gardens
    UTC -7ąDS

  7. #7
    4 Star Lounger
    Join Date
    Jul 2006
    Posts
    531
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: syntax to copy filename to another filename (latest)

    Ok, l will do that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •