Home / Microsoft / Microsoft DOS / create text file with name as date automaticly
0 Members and 2 Guests are viewing this topic. « previous next »
Pages: 1 2 [All] - (Bottom) Print
Author Topic: create text file with name as date automaticly  (Read 3953 times)
a117yogi
Guest
« on: November 04, 2005, 11:09:12 PM »

how do i create a txt file with the day it was created as the filename
IP logged
Sidewinder
Guru



Thanked: 97
Posts: 4,341

Experience: Familiar
OS: Windows 7

« Reply #1 on: November 05, 2005, 06:07:34 PM »

There are many different techniques to do this. Without knowing your OS I would be just guessing as to which one would work on your machine.

8)

PS. This question has been answered many times in this forum. A search of the Computer Hope forums may turn up an answer faster than posting.

Let us know.
IP logged

If you don't know where you are going, any road will get you there

                                                                            -Lewis Carroll
a117yogi
Guest
« Reply #2 on: November 06, 2005, 09:10:46 AM »

my os is windows 98 and i could not find any thing about what i need
IP logged
Sidewinder
Guru



Thanked: 97
Posts: 4,341

Experience: Familiar
OS: Windows 7

« Reply #3 on: November 06, 2005, 03:31:31 PM »

I guess a simple search is not what it once was. In any case, I don't recall when the /t switch became valid with the date command but this should work.

Code: [Select]

for /f "tokens=2-4 delims=/ " %%a in ('date /t') do (
     set mo=%%a
     set da=%%b
     set yr=%%c
     )

Once you have the %mo%, %da%, and %yr% variables, you can do most anything with them including naming files.

Good luck. 8)
IP logged

If you don't know where you are going, any road will get you there

                                                                            -Lewis Carroll
a117yogi
Guest
« Reply #4 on: November 06, 2005, 04:20:24 PM »

It d didint work

C:\WINDOWS\Desktop\bats>for /f "tokens=2-4 delims=/ " %a in
Syntax error

C:\WINDOWS\Desktop\bats> set mo=%a

C:\WINDOWS\Desktop\bats> set da=%b

C:\WINDOWS\Desktop\bats> set yr=%c

C:\WINDOWS\Desktop\bats> )
Bad command or file name

C:\WINDOWS\Desktop\bats>ren jornal\today.txt %a ,%b ,%c .txt
IP logged
Sidewinder
Guru



Thanked: 97
Posts: 4,341

Experience: Familiar
OS: Windows 7

« Reply #5 on: November 06, 2005, 04:53:02 PM »

Good grief, just how primitive is Win98? Always more than one way to do something:

Code: [Select]

@echo off
for /f "tokens=6-8 delims=/: " %%a in ('echo. ^| date') do (
           set mm=%%a
           set dd=%%b
           set yy=%%c
     )
echo %mm%-%dd%-%yr%


If you type echo. | date at the command line, you can see how to parse command output.  8)
IP logged

If you don't know where you are going, any road will get you there

                                                                            -Lewis Carroll
a117yogi
Guest
« Reply #6 on: November 07, 2005, 01:36:08 PM »

un fortunletly it still dont work
IP logged
Sidewinder
Guru



Thanked: 97
Posts: 4,341

Experience: Familiar
OS: Windows 7

« Reply #7 on: November 07, 2005, 02:47:06 PM »

Not to worry. Just a typo. ;D

Code: [Select]

@echo off
for /f "tokens=6-8 delims=/: " %%a in ('echo. ^| date') do (
 set mm=%%a
 set dd=%%b
 set yy=%%c
)
echo %mm%-%dd%-%yy%


Once you have isolated the date variables, you can use them wherever needed.

PS. Remember, I did warn you that a simple forum search would be faster then posting a question!

8)
« Last Edit: November 07, 2005, 02:49:03 PM by Sidewinder » IP logged

If you don't know where you are going, any road will get you there

                                                                            -Lewis Carroll
a117yogi
Guest
« Reply #8 on: November 08, 2005, 01:53:15 PM »

your going to hate me but it still dont work
IP logged
Sidewinder
Guru



Thanked: 97
Posts: 4,341

Experience: Familiar
OS: Windows 7

« Reply #9 on: November 08, 2005, 04:42:42 PM »

It would be helpful if you would let us know what results you do get. If you just type date at the command prompt, what comes up? if you type date /t at the command prompt, what comes up?

Show us some results!

8)
IP logged

If you don't know where you are going, any road will get you there

                                                                            -Lewis Carroll
a117yogi
Guest
« Reply #10 on: November 09, 2005, 02:28:02 PM »

date
C:\WINDOWS>date
Current date is Wed 11-09-2005
Enter new date (mm-dd-yy):


date /t
C:\WINDOWS>date /t

Invalid date
Enter new date (mm-dd-yy):
IP logged
Sidewinder
Guru



Thanked: 97
Posts: 4,341

Experience: Familiar
OS: Windows 7

« Reply #11 on: November 09, 2005, 03:32:13 PM »

Current date is Wed 11-09-2005

Code: [Select]

@echo off
for /f "tokens=5-7 delims=^-  " %%a in ('echo. ^| date') do (
 set mm=%%a
 set dd=%%b
 set yy=%%c
)
echo %mm%-%dd%-%yr%


Based on your results, this might work. I might add that these results look strange, but then so was Win98. [*sigh*]

8)
IP logged

If you don't know where you are going, any road will get you there

                                                                            -Lewis Carroll
a117yogi
Guest
« Reply #12 on: November 09, 2005, 05:44:23 PM »

here is the log
C:\WINDOWS\Desktop>for /f "tokens=5-7 delims=^-  " %a in ('echo. ^| date') do (

Syntax error

C:\WINDOWS\Desktop>  set mm=%a

C:\WINDOWS\Desktop>  set dd=%b

C:\WINDOWS\Desktop>  set yy=%c

C:\WINDOWS\Desktop> )
Bad command or file name

C:\WINDOWS\Desktop>echo %a -%b -
%a -%b -
IP logged
Sidewinder
Guru



Thanked: 97
Posts: 4,341

Experience: Familiar
OS: Windows 7

« Reply #13 on: November 09, 2005, 06:36:55 PM »

I admit there was a typo in the last post (I incorrectly used the other typo post as a guide, but you should at least get some output. I cannot recreate the syntax error even with the typo.

I couldn't find when the /f switch was first used with FOR, but I suspect it was after Win98. Are we talking Win98 or Win98SE?

Without the /f switch, I know of no way to parse in batch language. Windows Script is an option and is available free from Microsoft at WinScript 5.6...and yes, it runs on Win98.

Good luck. 8)
IP logged

If you don't know where you are going, any road will get you there

                                                                            -Lewis Carroll
uli_glueck
Guest
« Reply #14 on: November 10, 2005, 12:21:31 AM »

I found solutions to do it with dos.
Donīt know if it is working in  win98.

These are some solutions to get data in a variable:
http://www.student.northpark.edu/pemente/sed/bat_env.htm#firstword

For me the solution with debug works perfect.  :-)

You also can use the berkeley tools.
(Some unix commands for dos and windows shell.)
Use Google, I forgot the link.

hope this helps
good luck
uli

IP logged
a117yogi
Guest
« Reply #15 on: November 14, 2005, 03:26:21 PM »

i use win98 not win98se        

dont know if this helps but the win98 install disk was bad and i have to make do but maby the bad install messed up the dos programing

edit: maby it would be easer to put the date in a seporate file like a log and load it as a vairable
« Last Edit: November 14, 2005, 03:28:37 PM by a117yogi » IP logged
Pages: 1 2 [All] - (Top) Print 
Home / Microsoft / Microsoft DOS / create text file with name as date automaticly « previous next »
 


Login with username, password and session length

Old Forum Search | Forum Rules
Copyright © 2010 Computer Hope ® All rights reserved.
Powered by SMF 2.0 RC3 | SMF © 2006–2010, Simple Machines LLC
Page created in 0.085 seconds with 19 queries.