webdott
asked on
vb script creates new txt file, but not overwrite existing one
i have a vbs script that will create a new .txt file with today's date as the name
but if i run it on the same day, it overwrites the existing file.txt.
is there a way to have it create the name as today, if exists add +1
example:
2011-09-17.txt exists reate 2011-09-17-2.txt or 2011-09-17-v2.txt
thanks
but if i run it on the same day, it overwrites the existing file.txt.
is there a way to have it create the name as today, if exists add +1
example:
2011-09-17.txt exists reate 2011-09-17-2.txt or 2011-09-17-v2.txt
thanks
Dim TheDate, InputNote, fileOutput
REM TheDate is in YYYY-MM-DD format
TheDate = year(date) & "-" & right(100+month(date),2) & "-" & right(100+day(date),2)
InputNote = inputbox ("enter your note", "Note entry for " & date)
If InputNote="" then
Msgbox "Cancelled. No notes created."
wscript.quit
end if
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set fileOutput = objFSO.CreateTextFile("C:\mydocs\notes\" & TheDate & ".txt")
fileOutput.WriteLine InputNote
fileOutput.Close
Set objFSO = Nothing
ASKER
forgive me - i am new to vbs scripts.
how would i put that into my vbs script?
thanks
how would i put that into my vbs script?
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry meant to paste this in for alternative above:
Dim TheDate, InputNote, fileOutput
REM TheDate is in YYYY-MM-DD format
TheDate = year(date) & "-" & right(100+month(date),2) & "-" & right(100+day(date),2)
TheTime = right(100+hour(now),2) & ":" & right(100+minute(now),2) & ":" & right(100+second(now),2)
InputNote = inputbox ("enter your note", "Note entry for " & date & " at " & TheTime)
If InputNote="" then
Msgbox "Cancelled. No notes created."
wscript.quit
end if
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
Set fileOutput = objFSO.OpenTextFile("C:\my docs\notes \" & TheDate & ".txt",8,true)
fileOutput.WriteLine TheTime & chr(9) & InputNote
fileOutput.Close
Set objFSO = Nothing
As suggested in previous question for amending date formats etc. have a look at the options here:
https://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_1153-Using-dates-in-batch-files-scripts.html
Dim TheDate, InputNote, fileOutput
REM TheDate is in YYYY-MM-DD format
TheDate = year(date) & "-" & right(100+month(date),2) & "-" & right(100+day(date),2)
TheTime = right(100+hour(now),2) & ":" & right(100+minute(now),2) & ":" & right(100+second(now),2)
InputNote = inputbox ("enter your note", "Note entry for " & date & " at " & TheTime)
If InputNote="" then
Msgbox "Cancelled. No notes created."
wscript.quit
end if
Set objFSO = CreateObject("Scripting.Fi
Set fileOutput = objFSO.OpenTextFile("C:\my
fileOutput.WriteLine TheTime & chr(9) & InputNote
fileOutput.Close
Set objFSO = Nothing
As suggested in previous question for amending date formats etc. have a look at the options here:
https://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_1153-Using-dates-in-batch-files-scripts.html
Hi
Just added my code to existing one...
Dim TheDate, InputNote, fileOutput
TheDate = replace(replace(now,"/","_ "),":","_" )
set fso = createobject("scripting.fi lesystemob ject")
fso.createtextfile "D:\textfile_"×tamp&" .txt"
set fso = nothing
InputNote = inputbox ("enter your note", "Note entry for " & date)
If InputNote="" then
Msgbox "Cancelled. No notes created."
wscript.quit
end if
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
Set fileOutput = objFSO.CreateTextFile("C:\ " & TheDate & ".txt")
fileOutput.WriteLine InputNote
fileOutput.Close
Set objFSO = Nothing
Just added my code to existing one...
Dim TheDate, InputNote, fileOutput
TheDate = replace(replace(now,"/","_
set fso = createobject("scripting.fi
fso.createtextfile "D:\textfile_"×tamp&"
set fso = nothing
InputNote = inputbox ("enter your note", "Note entry for " & date)
If InputNote="" then
Msgbox "Cancelled. No notes created."
wscript.quit
end if
Set objFSO = CreateObject("Scripting.Fi
Set fileOutput = objFSO.CreateTextFile("C:\
fileOutput.WriteLine InputNote
fileOutput.Close
Set objFSO = Nothing
ASKER
that's what i need - thanks
We can create a text file by timestamp - it will be uniq always
''''''''''''''''''''''''''
timestamp = replace(replace(now,"/","_
set fso = createobject("scripting.fi
fso.createtextfile "D:\textfile_"×tamp&"
set fso = nothing
''''''''''''''''''''''''''