6 replies [Last post]
rmfred
rmfred's picture
Offline
Elder
Rock Springs, WY
Last seen: 3 years 38 weeks ago
Rock Springs, WY
Timezone: GMT-6
Joined: 2004-01-31
Posts: 1073
Points: 31

OK all you propeller beanie wearers... can this be done by dos batch file?

Can you increment a file name?
For example... a simple little batch file that runs once a week
@echo off
rem ** copy trans.fil to trans.txt **
copy c:\junk\trans.fil c:\junk\weekly\trans.txt
echo File Copy Complete
rem ** delete trans.fil **
del c:\junk\trans.fil
echo Trans File Deleted
rem ** Copy current trans.fil **
copy c:\tcs\trans.fil c:\junk\trans.fil
echo File Copy Complete
pause
exit

Now... is there any way I can add commands to do the following when this batch file is run next week?
When it copies trans.fil to c:\junk\weekly make it append a copy rather than to overwrite the existing txt file... so it would copy to trans1.txt and so on

I don't think it can be done... I am always up to working on a challenge... but I have yet come up with a way to do this.
TIA

Tags:
gary.turner
gary.turner's picture
Offline
Moderator
Dallas
Last seen: 1 year 17 weeks ago
Dallas
Timezone: GMT-6
Joined: 2004-06-25
Posts: 9776
Points: 3858

Way off topic... Dos Batch Files

I may be giving msdos more credit than it deserves, but you might try

type trans.fil >> trans.txt

cheers,

gary

If your web page is as clever as you can make it, it's probably too clever for you to debug or maintain.

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 7 years 25 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

Way off topic... Dos Batch Files

Ah Dos batch files, brings back memorys, can be quite useful.

This will likely not be any help and I cant think whether there is a method of incrementing file names which would be a stumbling block,
but you should be able to append files using 'copy'

copy textfile1.txt+ textfile2.txt+ textfile.txt

So I guess you could copy trans.fil and trans1.txt to a new file but as for incrementing ? but that would throw up obvious problems.

Don't quote me on any of the above Smile

Hugo.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

DCElliott
DCElliott's picture
Offline
Leader
Halifax, Canada
Last seen: 5 years 8 weeks ago
Halifax, Canada
Timezone: GMT-3
Joined: 2004-03-22
Posts: 828
Points: 0

Way off topic... Dos Batch Files

If you want to move beyond the limits of DOS batch files you should think of using the command language that has existed since Windows NT. There are many more commands, more error checking and commands that can be linked together an run only if the previous command completed successfully. It is also possible to append date and time stamps between appended sections (basically by echoing to a file the current date and time and then appending that to the archive file before bringing in the newest weekly file).

To have a look at the commands available go to start|run and type in cmd.exe to get a command window and then type help. Typing help command will give an explanation of how to use that command. There is an online reference at: http://labmice.techtarget.com/articles/batchcmds.htm

DE

David Elliott

Before you ask
LearnXHTML|CSS
ValidateHTML|CSS

rmfred
rmfred's picture
Offline
Elder
Rock Springs, WY
Last seen: 3 years 38 weeks ago
Rock Springs, WY
Timezone: GMT-6
Joined: 2004-01-31
Posts: 1073
Points: 31

Way off topic... Dos Batch Files

Thanks DE but unfortunately this is a Win98 box. It exists for only one reason... to poll and download the trans.fil from our remote fueling sites.

Once a week this file gets transferred into and processed by our accounting software... but there are times when I need a previous weeks file to verify some data or charges etc which I do in excel.

I keep about 5 weeks worth of files and do this manually by just renaming the trans.fil to say 0501-0507.fil and copying the current file into my weekly directory before transferring to accounting. However, when I am gone... this sometimes doesn't get done. The people I work with have a hard time even following written instructions... let alone doing simple things like renaming a file and copying and pasteing. I know this is hard to believe in this day and age, but trust me, it's the cross I have to bear... so I thought I would try to automate the process where all they have to do is click an icon to run the batch file.

What I've got now will work just fine as long as I am not gone for more than one week... if I'm gone for more than one week is where I would need the incrementation of the file name.

I guess I could just create two or more batch files... Week1, Week2 etc and have them click the appropriate icon for the week(Drunk I am gone...
i.e.
week1 does this: copy c:\junk\trans.fil c:\junk\weekly\trans1.txt
week2 does this: copy c:\junk\trans.fil c:\junk\weekly\trans2.txt

rmfred
rmfred's picture
Offline
Elder
Rock Springs, WY
Last seen: 3 years 38 weeks ago
Rock Springs, WY
Timezone: GMT-6
Joined: 2004-01-31
Posts: 1073
Points: 31

You can forget about it

Think I'll just create 3 little batch files and give them a menu to choose from...or separate icons to click

thanks for all your replies just the same

rmfred
rmfred's picture
Offline
Elder
Rock Springs, WY
Last seen: 3 years 38 weeks ago
Rock Springs, WY
Timezone: GMT-6
Joined: 2004-01-31
Posts: 1073
Points: 31

Way off topic... Dos Batch Files

OK... this seems to do the trick

Dim objFSO
varMonth = DatePart("m",Now())
varDay = DatePart("d",now())

Set objFSO = CreateObject("Scripting.FileSystemobject")

objFSO.CopyFile "c:\copy\trans.fil" , "c:\copy\weekly\rick" & "_" & varMonth & "_" & varDay & "_" & ".txt"

objFSO.DeleteFile "c:\copy\trans.fil"
objFSO.CopyFile "c:\tcs\trans.fil" , "c:\copy\trans.fil"

Set objFSO = Nothing

What do y'all think?

Thanks