1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Naming a file with yesterdays date

Discussion in 'Software Development' started by edsspuck11, Oct 28, 2011.

Thread Status:
Not open for further replies.
  1. edsspuck11

    edsspuck11 Thread Starter

    Joined:
    Oct 28, 2011
    Messages:
    1
    I use the following .bat file to rename a *.csv file with todays date. I need to be able to run the batch file and rename the file with yesterdays day. Can you help?

    C:\FPOS40\Bin\LVSRPT.exe Autolvs
    C:\FPOS40\Bin\MOVRPT.exe items_15min
    C:\FPOS40\Bin\ACTRPT.exe Auto_pickup
    C:\FPOS40\Bin\PDOUTRPT.exe Paidouts
    C:\FPOS40\Bin\MOVRPT.exe all_items
    c:\fpos40\bin\VIRPT.exe VoidItemRPT

    SET DDMMYY=
    SET YEAR=

    REM PLACE PATH TO EXECUTABLE HERE
    REM ******************************************************************

    C:\FPOSRPT\LC\csvfiles



    REM THIS PART CREATES THE DATE IN DDMMYY FORMAT
    REM ******************************************************************

    FOR /F "TOKENS=1-4 DELIMS=/ " %%A IN ("%DATE%") DO SET DD=%%B
    FOR /F "TOKENS=1-4 DELIMS=/ " %%A IN ("%DATE%") DO SET MM=%%C
    FOR /F "TOKENS=1-4 DELIMS=/ " %%A IN ("%DATE%") DO SET YEAR=%%D

    SET YY=%YEAR:~2,4%
    SET DDMMYY=%DD%%MM%%YY%


    REM THIS PART RENAMES YOUR FILE USING TODAY'S DATE - %DDMMYY%
    REM JUST REPLACE "path to file" WITH THE PATH OF THE REPORT EXPORT
    REM ******************************************************************

    rem REN C:\path to file %DDMMYY%.CSV

    REN C:\FPOSRPT\LC\csvfiles\SBR\Create_CSV\sbr.csv ???%DDMMYY%.CSV
    REN C:\FPOSRPT\LC\csvfiles\LVS\Create_CSV\lvs.csv ???%DDMMYY%.CSV
    REN C:\FPOSRPT\LC\csvfiles\Item_movement\Create_CSV\Items.csv ?????%DDMMYY%.CSV
    REN C:\FPOSRPT\LC\csvfiles\DROP\Create_CSV\Drop.csv ????%DDMMYY%.CSV
    REN C:\FPOSRPT\LC\csvfiles\Paidouts\Create_CSV\PDO.csv ???%DDMMYY%.CSV
    REN C:\FPOSRPT\LC\csvfiles\AllItems\Create_CSV\Allitems.csv ????????%DDMMYY%.CSV
    REN C:\FPOSRPT\LC\csvfiles\VOID\Create_CSV\VOID.csv ????%DDMMYY%.CSV
     
  2. Keebellah

    Keebellah Trusted Advisor

    Joined:
    Mar 27, 2008
    Messages:
    6,608
    First Name:
    Hans
    Maybe this will help you.
    I use a vbs cript to set may daily variables, I cleande the script to just create a TODAY and a YESTERDAY

    What the vbs script does is create a batch file in the Temp folder name Envars.bat
    I also editted the batch file you posted showing you how I did it;


    The idea is to create a folder C:\BAT
    If this is not possibel then you will have to create the folder wher you want but edit the GetVars.Bat so it points to the vbs script that needs to be there too.

    You start your own batch file
    call GetVars.Bat
    which triggers the vbs script and EnvVar.Bat is run
    the variables TODAY and YESTERDAY are available for use

    Check YourBatch.bat to see what I did, and don't forget to edit the C:\Bat if it's different

    I hope my explanation helps you, else just test it
     

    Attached Files:

  3. Keebellah

    Keebellah Trusted Advisor

    Joined:
    Mar 27, 2008
    Messages:
    6,608
    First Name:
    Hans
    To make GetVars.Bat more versatile

    Code:
    @echo off
    TITLE = Setting variables  . .
    rem EnvVars.bat wordt aangeroepen de de variabelen kunnen gebruikt worden.
    rem Om de variabelen te tonen kan EnvShow.bat gebruikt worden
    if exist %TEMP%\OK.txt del %TEMP%\OK.txt
    if exist %TEMP%\EnvVars.Bat del %TEMP%\EnvVars.bat
    [COLOR="Red"]SET ePATH=%CD%[/COLOR]
    Wscript %ePATH%\SetVars.vbs
    :repeat
    if not exist %TEMP%\OK.txt goto repeat
    TITLE = Calling variable . . .
    CALL %TEMP%\EnvVars.Bat
    
    The red line checks the path Getvars.Bat is in and looks there for Setvars.vbs, this makes it easier to use, just call the <path> getvars.bat and it works
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1024451

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice