On Sat, 17 Jul 2021, Sven Schreiber wrote:
Am 17.07.2021 um 22:32 schrieb Sven Schreiber:
> A space in the file name (path) alone doesn't cause an error, at least
> not in "readfile" nor in mwrite. I tested this with a subdirectory with
> spaces.
> Maybe the case where there's a blank in the user name part of the path
> is different (always on Windows...). I will try more testing to pinpoint
> the cause of the error.
Hm, perhaps a blank in the user name really does make a difference.
Here's what I did for testing:
1. Create a new user account on the (Win 10) system, named "account with
blank".
2. Create the trivial text file "C:\Users\account with
blank\Documents\gretl\oha.txt", which contains just a single line of
short but arbitrary text.
3. Run the following script [...]
I can't replicate this problem on Windows 10 using the July 14
snapshot (but snapshot date shouldn't matter since nothing has
changed in this respect lately).
I added an account under the name "dummy user" and created a file
"C:\Users\dummy user\Documents\gretl\oha.txt" with content "A few
words". Here's my first script (from Sven):
<hansl>
print $workdir
string psep = $windows ? sprintf("\\") : "/"
# check whether dir exists, is reachable by gretl
m = I(2)
mwrite(m, $workdir ~ psep ~ "mym.mat")
# now the readfile thing
string fpath = $workdir ~ psep ~ "oha.txt"
print fpath
string s = readfile(fpath)
print s
</hansl>
Here's my output:
<output>
? print $workdir
C:\Users\dummy user\Documents\gretl
? string psep = $windows ? sprintf("\\") : "/"
Generated string psep
# check whether dir exists, is reachable by gretl
? m = I(2)
Generated matrix m
? mwrite(m, $workdir ~ psep ~ "mym.mat")
# now the readfile thing
? string fpath = $workdir ~ psep ~ "oha.txt"
Generated string fpath
? print fpath
C:\Users\dummy user\Documents\gretl\oha.txt
? string s = readfile(fpath)
Generated string s
? print s
A few words
</output>
Here's a second, integrated script which combines write and read:
<hansl>
clear
fpath = sprintf("%s\\oha.txt", $workdir)
printf "fpath='%s'\n", fpath
outfile "@fpath" --quiet
print "A few more words"
end outfile
string s = readfile(fpath)
print s
</hansl>
<output>
? clear
? fpath = sprintf("%s\\oha.txt", $workdir)
Generated string fpath
fpath='C:\Users\dummy user\Documents\gretl\oha.txt'
? outfile "@fpath" --quiet
Now writing output to 'C:\Users\dummy user\Documents\gretl\oha.txt'
Closed output file 'C:\Users\dummy user\Documents\gretl\oha.txt'
? string s = readfile(fpath)
Generated string s
? print s
A few more words
</output>
I recommend examining the path string in question using printf and
wrapping in single quotes, to check that you haven't got any leading
or trailing spaces. Might also be worth checking for non-breaking
space in place of a proper space.
Allin