Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > microsoft.public.scripting.vbscript > #12415
| From | JJ <jj4public@gmail.com> |
|---|---|
| Newsgroups | microsoft.public.scripting.vbscript |
| Subject | EOL type detection |
| Date | 2022-03-05 15:39 +0700 |
| Organization | A noiseless patient Spider |
| Message-ID | <bb79q57z2c92.16pyyy6q0tjfm.dlg@40tude.net> (permalink) |
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]
Back to microsoft.public.scripting.vbscript | Previous | Next — Next in thread | Find similar
EOL type detection JJ <jj4public@gmail.com> - 2022-03-05 15:39 +0700
Re: EOL type detection "Mayayana" <mayayana@invalid.nospam> - 2022-03-05 08:57 -0500
Re: EOL type detection JJ <jj4public@gmail.com> - 2022-03-06 06:27 +0700
Re: EOL type detection "R.Wieser" <address@not.available> - 2022-03-05 15:49 +0100
Re: EOL type detection JJ <jj4public@gmail.com> - 2022-03-06 06:28 +0700
Re: EOL type detection "R.Wieser" <address@not.available> - 2022-03-06 10:06 +0100
Re: EOL type detection JJ <jj4public@gmail.com> - 2022-03-08 05:36 +0700
Re: EOL type detection "R.Wieser" <address@not.available> - 2022-03-08 11:03 +0100
Re: EOL type detection JJ <jj4public@gmail.com> - 2022-03-09 09:30 +0700
csiph-web