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

Author Topic: script file to add date to file name  (Read 3277 times)

0 Members and 1 Guest are viewing this topic.

asha

    Topic Starter


    Newbie

    • Experience: Beginner
    • OS: Windows 10
    script file to add date to file name
    « on: October 19, 2017, 11:49:13 AM »
    Hello Folks,

    Have a small problem that I'm hoping I could get some assistance with.  I currently have a batch file which that that ftp's a .txt to a desired location. I want to rename this text file with current month in abbreviation and year  to the filename my filename is MISFTP.txt it should be rename to be something like 102<Mon'17>.txt  i.e 102oct'17


    USER user   
    PASS password
    CONNECT "gggggg"
    ONERROR GOTO DISCONNECT
    cd MISFTP
    MPUT MISFTP.txt
    RNFR /home/ssattu/MISFTP/MISFTP.txt
    RNTO /home/ssattu/MISFTP/102.txt
    LABEL DISCONNECT
    CLOSE

    Squashman



      Specialist
    • Thanked: 134
    • Experience: Experienced
    • OS: Other
    Re: script file to add date to file name
    « Reply #1 on: October 20, 2017, 08:48:21 AM »
    You don't need to use the rename command.  You can name it when you use the put the command.
    Code: [Select]
    PUT MISFTP.txt 102oct17.txt

    Squashman



      Specialist
    • Thanked: 134
    • Experience: Experienced
    • OS: Other
    Re: script file to add date to file name
    « Reply #2 on: October 20, 2017, 03:18:25 PM »
    If you are looking for a way to get the month name and century into variables to use to build your FTP script, this should help you with that.
    Code: [Select]
    @echo off
    setlocal EnableDelayedExpansion
    set m=100
    for %%m in (January February March April May June July August September October November  December) do (
       set /A m+=1
       set month[!m:~-2!]=%%m
    )
    for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
    set cc=%dt:~2,2%
    set mm=%dt:~4,2%
    set monthName=!month[%mm%]!
    echo Month Name: %monthName%
    echo    Century: %cc%
    pause