Du kan bruge denne her, den åbner filen og skriver filindholdet med
filnavnet på øverste linie.
'****************'
Dim filnavn, sfil, filsti
Dim f 'As TextStream
Dim fso 'As FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
filsti = "c:\temp\test.txt"
filnavn = fso.GetFileName(filsti)
Set f = fso.OpenTextFile(filsti,1)
sfil = f.ReadAll()
f.Close
Set f = fso.OpenTextFile(filsti,2)
f.Write filnavn & vbCrLf & sfil
f.Close
Set f = Nothing
Set fso = Nothing
*****************************
"Sune" <sm@kmc.dk> skrev i en meddelelse
news:3bb43d82$0$51418$edfadb0f@dspool01.news.tele.dk...
> Jaaa - den virker hvis jeg kører den i en Excel makro, men hvis jeg kører
> den bare ved at klikke på den - test.vbs fejler den med "Slut på sætning
var
> ventet" efter " Open "C:\Temp\test.txt" ".
>
> Har du et godt forslag til hvorfor ??
>
> Sune
>
> "Harald Staff" <harald.staff@nrk.no> skrev i en meddelelse
> news:9ovhlu$o9l$1@oslo-nntp.eunet.no...
> > OK. Filesystem har jeg for liten erfaring med. Men jeg tror på denne
> > allikevel:
> >
> > 'bla bla, inntil
> > ' Else
> > ' 'The file name has no dot
> > ' fil.Name = fil.Name & strDate
> > ' End If
> >
> > Open "C:\Temp\test.txt" For Output As #1
> > Print #1, fil.Name
> > Close #1
> >
> > If Err.Number <> 0 Then Wscript.Quit 1
> > 'og så er det snart slut
> >
> > HTH. Beste hilsen Harald
> >
> > Sune <sm@kmc.dk> skrev i
> > news:3bb334b9$0$80724$edfadb0f@dspool01.news.tele.dk...
> > >
> > >
> > >
> > > "Harald Staff" <harald.staff@nrk.no> skrev i en meddelelse
> > > news:9ovc0n$arr$1@oslo-nntp.eunet.no...
> > > > Hei Sune
> > > >
> > > > Sub SkrivTextFil()
> > > > Open "C:\Temp\test.txt" For Output As #1
> > > > Print #1, "Her er selve teksten"
> > > > Close #1
> > > > End Sub
> > > >
> > > >
> > > > Jeg er usikker på hva koden din er, så jeg har ikke implementeret
den.
> > Er
> > > > "fil" et objekt med property Name, eller er det en (deklarert ?)
> > variabel
> > > > som inneholder punktum ?
> > > >
> > > > OK, det finner du ut av.
> > > >
> > > > HTH. Beste hilsen Harald
> > > >
> > > klip..........
> > >
> > > Hej Harald,
> > >
> > > Shit du er hurtig
)
> > >
> > > Du får lige hele scriptet her :
> > >
> > > ---------------------
> > > Option Explicit
> > > On Error Resume Next
> > > ' This script renames a file by appending the current date
> > > ' to the beginning of the file name. Pass the file name as an
> > > ' argument. Pass the long or short file name with a full path!
Example:
> > > ' start /w DateName.vbs "C:\Program Files\Fnord Web
> Server\logs\Reference
> > > Log.txt"
> > > ' Would rename "C:\Program Files\Fnord Web Server\logs\Reference
> Log.txt"
> > > ' to "C:\Program Files\Fnord Web Server\logs\1999-12-28-Reference
> Log.txt"
> > >
> > > '''''''''' Declare variables and objects
> > > Dim strFileName 'As String
> > > Dim strShortName 'As String
> > > Dim strDate 'As String
> > > Dim fs 'As Scripting.FileSystemObject
> > > Dim fol 'As Scripting.Folder
> > > Dim fils 'As Scripting.Files
> > > Dim fil 'As Scripting.File
> > >
> > > ''''''''''Create the fs object
> > > Set fs = Wscript.CreateObject("Scripting.FileSystemObject")
> > >
> > > ''''''''''First check the filename argument
> > > If Wscript.Arguments.Count <> 1 Then
> > > MsgBox "You must pass a path & file name on the command line"
> > > Wscript.Quit 1
> > > End If
> > > strFileName = Wscript.Arguments(0)
> > > If Not fs.FileExists(strFileName) Then
> > > MsgBox Wscript.Arguments(0) & " is not a legitimate file name."
> > > Wscript.Quit 1
> > > End If
> > > Set fil = fs.GetFile(strFileName)
> > > strShortName = fil.ShortName
> > > Set fil = Nothing
> > >
> > > ''''''''''Now get the date into the format we want
> > > strDate = Year(Now) & "" & Right("0" & Month(Now),2) & "" & Right("0"
&
> > > Day(Now),2) & ""
> > >
> > > ''''''''''Find the long file name. Search the directory. Yuk.
> > > Set fol = fs.GetFolder(fs.BuildPath(strFileName, "..\"))
> > > Set fils = fol.Files
> > > For Each fil In fils
> > > If fil.ShortName = strShortName Then Exit For
> > > Next
> > > If fil.ShortName <> strShortName Then
> > > MsgBox "Oops -- I can't seem to locate that file"
> > > Wscript.Quit 1
> > > End If
> > >
> > > ''''''''''Now warn the user we are about to make a change
> > > 'If MsgBox ("This program will rename """ & fil.Name & """ to """ &
> > strDate
> > > & fil.Name & """. Continue?", vbOkCancel) = vbCancel Then Wscript.Quit
1
> > >
> > > ''''''''''Now rename it
> > > fil.Name = strDate & fil.Name
> > > ' Use the below code to put date code at end of the file name but
before
> > the
> > > extension
> > > ' If InstrRev(fil.Name, ".") > InstrRev(fil.Name, "\") Then
> > > ' 'The file name has a dot
> > > ' fil.Name = Left(fil.Name, InstrRev(fil.Name, ".") - 1) & strDate
&
> > > Mid(fil.Name, InstrRev(fil.Name, "."))
> > > ' Else
> > > ' 'The file name has no dot
> > > ' fil.Name = fil.Name & strDate
> > > ' End If
> > >
> > > If Err.Number <> 0 Then Wscript.Quit 1
> > >
> > > ''''''''''Clean up
> > > Set fil = Nothing
> > > Set fol = Nothing
> > > Set fs = Nothing
> > >
> > >
> > > Mvh,
> > >
> > > Sune
> > >
> > >
> > >
> >
> >
>
>