Results 1 to 4 of 4

Thread: Batch file to rename a file

  1. #1
    Join Date
    Sep 2010
    Posts
    2

    Batch file to rename a file

    I'm not sure where to post this but I hope someone can help.

    I require a batch file that will normally start a program on a daily basis. However when the system reaches a certain date it must start an alternative program.

    Basically this is what I need:

    if %date% is not eqaul to "ddmmyyyy" then goto normal
    alternative.exe
    exit
    normal.exe
    exit

  2. #2
    Join Date
    Dec 2007
    Posts
    1,736

    Re: Batch file to rename a file

    There are many command line program, one such called is Datedir which is intended mainly for use in batch files. Give it the name of an existing folder, and it will rename that folder with an integer representing the current date. Alternatively, with no parameters, the command "datedir" will create a new folder named for the current date. Or you can write a simple batch file to start a program when you start your computer:

    1. Open notepad. It is located at Start Menu>All Programs>Accessories>Notepad (Windows XP)
    2. Then type start frontpg.exe
    3. Choose File from the menu above. Then choose Save As
    4. Navigate to save on the desktop and type the file name in with .bat filename extension. I have called mine startup.bat
    5. Now you can double click on it on the desktop to test if it opens FrontPage

  3. #3
    Join Date
    Sep 2010
    Posts
    2

    Re: Batch file to rename a file

    Thanks James but I'm not sure if that's exactly what I require.

    Lets say I have a batch file that looks like this:

    @echo off
    cls
    echo Today is %date%
    If %date% is not equal to "ddmmyyy" the goto start
    :alternative
    rename xyz.dbf 123.dbf
    goto exit
    :start
    strtprog.exe
    :exit


    But I need to know the correct syntax of the If %date% is not equals

  4. #4
    Join Date
    Dec 2007
    Posts
    996

    Re: Batch file to rename a file

    You can rename a file and add a date stamp like this:

    ren h:\test\hello.txt hello%date%.txt

    If you want to add date stamp to all files in a folder, you can use this:

    h:
    cd test
    for %%i in (*.*) do ren %%i %%i-%date%.txt

    You can paste either of the source codes into notepad and save the file as xxx.cmd or xxx.bat

Similar Threads

  1. How to rename Batch File with Windows PowerShell
    By Akiraa in forum Tips & Tweaks
    Replies: 0
    Last Post: 25-08-2012, 12:06 PM
  2. Learning Batch file to open a program or a file
    By Ikshana in forum Windows Software
    Replies: 3
    Last Post: 04-04-2011, 07:24 PM
  3. Windows Batch file to output directory names and size to txt file
    By m2thearkus in forum Software Development
    Replies: 6
    Last Post: 16-07-2010, 12:04 AM
  4. Dos batch file to sort files based on file names.
    By Jon Osborn in forum Windows Server Help
    Replies: 9
    Last Post: 17-06-2009, 11:06 AM
  5. Replies: 3
    Last Post: 12-03-2009, 12:56 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,874,573.14457 seconds with 17 queries