|
| Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free! |
batch file:Insert date in file
|
Original Message
|
Name: Noor2000
Date: August 29, 2004 at 08:44:36 Pacific
Subject: batch file:Insert date in file OS: Windows2000 CPU/Ram: 256
|
Comment: Hi all, every day, I have to open a text file to insert in the first line the current date and then print, and I'm wondering If I could do that by a batch file? Thanks for any help Noor(TechnicalUser)
Report Offensive Message For Removal
|
|
Response Number 1
|
Name: IVO
Date: August 29, 2004 at 13:52:28 Pacific
|
Reply: (edit)The following batch achieves your wish and the code is planned to perform in the safest way possible. I named it CDate.bat and to run type CDate Path_Name\File_Name (e.g. CDate C:\MyDir\MyFile.txt). It works under Win NT/2K/XP only and file names with embedded blanks are not allowed. @Echo Off If "%1"=="" (Echo File missing & GoTo :EOF) If not exist %1 (Echo File not found & GoTo :EOF) Echo To-day Date is %Date% > %0.txt Echo. >> %0.txt Type %1 >> %0.txt Type %0.txt > Prn Ren %~f1 %~n1.bak Move %0.txt %~f1 > Nul If not ErrorLevel 1 Del %~dpn1.bak I tested it under Win XP/2K and the code worked fine, any way if you need more support or anything goes wrong post again.
Report Offensive Follow Up For Removal
|
|
Response Number 2
|
Name: Noor2000
Date: August 30, 2004 at 09:02:34 Pacific
|
Reply: (edit)Hi IVO, It works but when I run the script, the script doesn't finish It is like It is blocked, I don't know If you get the same problem Thanks Noor
Report Offensive Follow Up For Removal
|
|
Response Number 3
|
Name: IVO
Date: August 30, 2004 at 09:17:44 Pacific
|
Reply: (edit)When I tested I found no problems at all... Could you specify better the line which it hangs on removing the @Echo Off statement? That will help me to troubleshoot.
Report Offensive Follow Up For Removal
|
|
Response Number 4
|
Name: Noor2000
Date: August 30, 2004 at 09:29:36 Pacific
|
Reply: (edit)Hi IVO, When I deactivated the line: Type %0.txt > Prn, It works but the date is written at the same file, I don't understand very well what do you do at the end(the 4 lines at the and), I see the help of the commands but i still confused. If you could give me more explanation, I will appreciate it Thanks
Report Offensive Follow Up For Removal
|
|
Response Number 5
|
Name: IVO
Date: August 31, 2004 at 01:27:49 Pacific
|
Reply: (edit)Here you find a slightly modified version of my script that should work without troubles. The main variant is printing via NotePad instead of redirecting the Type command to the printer. I suppose you have your printer connected via USB leading the Type command to hang. The script makes up a temp file named CDate.txt (%0 is resolved by assigning the name of the current batch) holding in the first line the date and appending the original document. The temp file is printed using NotePad and then substituted (Move) to the original one. If you get any trouble, post again. @Echo Off If "%1"=="" (Echo File missing & GoTo :EOF) If not exist %1 (Echo File not found & GoTo :EOF) Echo. Echo Printing %~f1 with to-day date: %Date% Echo To-day Date is %Date% > %0.txt Echo. >> %0.txt Type %1 >> %0.txt NotePad /P %0.txt Move %0.txt %~f1
Report Offensive Follow Up For Removal
|
|
Response Number 6
|
Name: Noor2000
Date: September 1, 2004 at 11:22:17 Pacific
|
Reply: (edit)IVO, that works fine, except that I don't know when the file is printed I got the name of the scrpt cdate.bat.txt, If possible no. Another question, is it possible to check that this file was created the same day If not give an error message I hope I'm not abusing Thanks alot Noor
Report Offensive Follow Up For Removal
|
|
Response Number 7
|
Name: IVO
Date: September 2, 2004 at 01:55:06 Pacific
|
Reply: (edit)Noor, I am glad to help you in the best way I can, as my style is to do the job so full satisfaction is achieved. to get that target however I must understand exactly what you wish and your last post is quite confusing to me (English is not my native language, I'm italian). So please explain what you want trying to be clear and exact and you get my help.
Report Offensive Follow Up For Removal
|
|
Response Number 8
|
Name: Noor2000
Date: September 2, 2004 at 11:56:07 Pacific
|
Reply: (edit)Hi Ivo, Sorry if I didn't explain as I should. In my job every morning, I have a batch which is run automatically and every day I have to open this file (its name is vdetails.txt), to put the date on it and then to print it. The problem with the script you gave, It prints Cdate.bat.txt as a title in the file, so when I print the file after runing your script, I have Cdate.bat.txt in every page and my second question is, for some reason, sometimes I have an old file (the file of yesterday) and I should not work with that, my quest is if possible to check that the file was created the same day I'm going to print it. Is it okey Thanks Noor
Report Offensive Follow Up For Removal
|
|
Response Number 9
|
Name: IVO
Date: September 2, 2004 at 13:14:14 Pacific
|
Reply: (edit)Hi Noor, now I understand what is the problem regarding either the format of the print document either the date issue. I need a bit to solve both, so you'll get my answer tomorrow. But... while the last requires only some added code, the first is more subtle as it is due NotePad itself. So please I need more info to go further: 1) Have you administrator's privilege to set your printer shared? If so we can solve in a very cool way. 2) Let me know how your printer is connected (e.g. local USB printer). Waiting for your info I'm starting to work.
Report Offensive Follow Up For Removal
|
|
Response Number 10
|
Name: Noor2000
Date: September 2, 2004 at 13:45:35 Pacific
|
Reply: (edit)Hi Ivo, Our printer is set by an IP Port. I think It is not really important to print the file using notepad. When the file is created with the date,I will just use LPR to send it to the printer, If I can just get rid of the title: Cdate.bat.txt that will be great The second question I don't know how to do it, I would love to see it as you: just some code to add Thanks Noor
Report Offensive Follow Up For Removal
|
|
Response Number 11
|
Name: IVO
Date: September 2, 2004 at 14:30:57 Pacific
|
Reply: (edit)To add the code is a nut, trust me, but regarding the printing question you must use NotePad in the case we are working on (too complex to explain why, take it for granted). So we can select two roads: 1) Strip the header from NotePad Requires a registry modification with RegEdit and administrator's privilege. 2) Sharing the printer using Net Use command Requires \\ComputerName\SharedName where ComputerName is your own workstation name and SharedName the printer shared name if a network printer. The second way leads to then use a Print command instead of NotePad. Let me know the road you want to take. I do not know LPR so if that suffices for you, I can just insert tha date and check for to-day creation generating a txt file without the command to print it.
Report Offensive Follow Up For Removal
|
|
Response Number 12
|
Name: IVO
Date: September 3, 2004 at 03:45:26 Pacific
|
Reply: (edit)Hi Noor, Check your in-box as I mailed you the ultimate version/notes due to the lenght of the text. I hope that helps you and have a nice day.
Report Offensive Follow Up For Removal
|

Post Locked
This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
Go to Programming Forum Home
|
|
|