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

Author Topic: Batch file creation  (Read 2409 times)

0 Members and 1 Guest are viewing this topic.

Jethrocreek

  • Guest
Batch file creation
« on: August 29, 2007, 05:51:22 PM »
I am trying to make a batch file that will copy a given file and rename it with that day's date
(I.E. copy c:\AMM.MDB to d:\8-29-07.MDB)
But don't know the scripting involved in what I thought would be a simple task. I can get a copy and I can rename it to whatever I want but, I can't get it to use the day's particular date as the name.

Computer Hope Admin

  • Administrator


  • Prodigy

    Thanked: 248
    • Yes
    • Yes
    • Yes
    • Computer Hope
  • Certifications: List
  • Computer: Specs
  • Experience: Guru
  • OS: Windows 10
Re: Batch file creation
« Reply #1 on: August 29, 2007, 06:39:01 PM »
The line you'd want to add is something similar to the below example.

FOR /F "TOKENS=1-5 DELIMS=/ " %%D IN ("%DATE%") DO RENAME "AMM.MDB" %%E-%%F-%%G.MDB

This example takes the %DATE% tag which is the systems current date and splits it by spaces and slashes. So the date tag: Wed 08/29/2007 would be split into the variables starting with %%D (so Wed 08 29 2007).

Hope that helps.
Everybody is a genius. But, if you judge a fish by its ability to climb a tree, it will spend its whole life believing that it is stupid.
-Albert Einstein

Jethrocreek

  • Guest
Re: Batch file creation
« Reply #2 on: August 29, 2007, 08:04:34 PM »
Will give it a shot thanks so much.

Computer Hope Admin

  • Administrator


  • Prodigy

    Thanked: 248
    • Yes
    • Yes
    • Yes
    • Computer Hope
  • Certifications: List
  • Computer: Specs
  • Experience: Guru
  • OS: Windows 10
Re: Batch file creation
« Reply #3 on: August 29, 2007, 08:36:35 PM »
You're welcome. Did notice that I was renaming the file and you wanted to copy, so instead of rename you may want to change to copy.
Everybody is a genius. But, if you judge a fish by its ability to climb a tree, it will spend its whole life believing that it is stupid.
-Albert Einstein

Jethrocreek

  • Guest
Re: Batch file creation
« Reply #4 on: August 29, 2007, 08:46:53 PM »
Okay. change of thought I got it. Thank you so much. By the way anyone wanna see it:

@ECHO OFF
:START
COPY C:\PROGRA~1\ANTEQM~1\Data\AMM.MDB "D:\Anteq\Data" /Y
FOR /F "TOKENS=1-5 DELIMS=/ " %%D IN ("%DATE%") DO RENAME "D:\Anteq\Data\AMM.MDB" %%E-%%F-%%G.MDB

Computer Hope Admin

  • Administrator


  • Prodigy

    Thanked: 248
    • Yes
    • Yes
    • Yes
    • Computer Hope
  • Certifications: List
  • Computer: Specs
  • Experience: Guru
  • OS: Windows 10
Re: Batch file creation
« Reply #5 on: August 29, 2007, 08:50:34 PM »
I'm not sure if I understand you fully, but if you're running the batch file from a different directly simply place the full path name in the FOR line. For example:

FOR /F "TOKENS=1-5 DELIMS=/ " %%D IN ("%DATE%") DO RENAME "d:\anteq\data\AMM.MDB" %%E-%%F-%%G.MDB

Unless a batch file is in the same directly the full path of where the file is located will be required.
Everybody is a genius. But, if you judge a fish by its ability to climb a tree, it will spend its whole life believing that it is stupid.
-Albert Einstein

Jethrocreek

  • Guest
Re: Batch file creation
« Reply #6 on: August 29, 2007, 08:51:47 PM »
Yup I got it. I was changing the topic as you replied. Thanks for the help. much appreciated.

Computer Hope Admin

  • Administrator


  • Prodigy

    Thanked: 248
    • Yes
    • Yes
    • Yes
    • Computer Hope
  • Certifications: List
  • Computer: Specs
  • Experience: Guru
  • OS: Windows 10
Re: Batch file creation
« Reply #7 on: August 29, 2007, 09:18:53 PM »
You're welcome.
Everybody is a genius. But, if you judge a fish by its ability to climb a tree, it will spend its whole life believing that it is stupid.
-Albert Einstein