JJ
2022-03-05 08:39:26 UTC
For example, below code creates two files: `unix` and `dos`. Each is written
with two lines: `123` then `abc`. Using LF EOL for the `unix` file, and CRLF
for the `dos` file.
FileSystemObject apparently support both EOL format when reading file, as
shown in below code. It properly read each line as having 3 characters.
[code]
set fs = createobject("scripting.filesystemobject")
set funix = fs.createtextfile("unix")
funix.write "123" & vblf & "abc" & vblf
funix.close
set fdos = fs.createtextfile("dos")
fdos.write "123" & vbcrlf & "abc" & vbcrlf
fdos.close
set funix = fs.opentextfile("unix")
unix1 = funix.readline
unix2 = funix.readline
funix.close
wsh.echo "unix file size = " & fs.getfile("unix").size
wsh.echo "unix1: len=" & len(unix1) & ", str='" & unix1 & "'"
wsh.echo "unix2: len=" & len(unix2) & ", str='" & unix2 & "'"
fs.deletefile "unix"
set fdos = fs.opentextfile("dos")
dos1 = fdos.readline
dos2 = fdos.readline
fdos.close
wsh.echo "dos file size = " & fs.getfile("dos").size
wsh.echo "dos1: len=" & len(dos1) & ", str='" & dos1 & "'"
wsh.echo "dos2: len=" & len(dos2) & ", str='" & dos2 & "'"
fs.deletefile "dos"
[/code]
The problem is that, there doesn't seem to be a way to retrieve the EOL type
detected by FileSystemObject. In this case, we'd have to manually implement
the EOL detection ourselves. Currently, I'm doing it like below, but IMO,
it's a bit tedious. So, it there a simpler method.
[code]
set f = fs.opentextfile("thefile")
s = f.readline
f.close
set f = fs.opentextfile("thefile")
f.skip len(s)
on error resume next
doseol = f.read(1) = vbcr
if err.number <> 1 then doseol = 1
f.close
'doseol: 0=unix, -1=dos, 1=unknown (no EOL in file)
[/code]
with two lines: `123` then `abc`. Using LF EOL for the `unix` file, and CRLF
for the `dos` file.
FileSystemObject apparently support both EOL format when reading file, as
shown in below code. It properly read each line as having 3 characters.
[code]
set fs = createobject("scripting.filesystemobject")
set funix = fs.createtextfile("unix")
funix.write "123" & vblf & "abc" & vblf
funix.close
set fdos = fs.createtextfile("dos")
fdos.write "123" & vbcrlf & "abc" & vbcrlf
fdos.close
set funix = fs.opentextfile("unix")
unix1 = funix.readline
unix2 = funix.readline
funix.close
wsh.echo "unix file size = " & fs.getfile("unix").size
wsh.echo "unix1: len=" & len(unix1) & ", str='" & unix1 & "'"
wsh.echo "unix2: len=" & len(unix2) & ", str='" & unix2 & "'"
fs.deletefile "unix"
set fdos = fs.opentextfile("dos")
dos1 = fdos.readline
dos2 = fdos.readline
fdos.close
wsh.echo "dos file size = " & fs.getfile("dos").size
wsh.echo "dos1: len=" & len(dos1) & ", str='" & dos1 & "'"
wsh.echo "dos2: len=" & len(dos2) & ", str='" & dos2 & "'"
fs.deletefile "dos"
[/code]
The problem is that, there doesn't seem to be a way to retrieve the EOL type
detected by FileSystemObject. In this case, we'd have to manually implement
the EOL detection ourselves. Currently, I'm doing it like below, but IMO,
it's a bit tedious. So, it there a simpler method.
[code]
set f = fs.opentextfile("thefile")
s = f.readline
f.close
set f = fs.opentextfile("thefile")
f.skip len(s)
on error resume next
doseol = f.read(1) = vbcr
if err.number <> 1 then doseol = 1
f.close
'doseol: 0=unix, -1=dos, 1=unknown (no EOL in file)
[/code]