Page 1 of 1

cannot copy file with special char in windows

Posted: 06 Jul 2018 13:56
by Misska
Hello,

I am currently working on a lua extension to sort my music.
The tool moves files from a 'unsorted' folder to a defined 'sorted' folder (or to trash).

The tool is working perfectly on Linux, but I getting in trouble with Windows.
my script uses :
os.execute ('cmd mkdir <my_unsorted_folder/album/')
to create the sorted folder

os.execute ('cmd copy /B /Y /V "<my_unsorted_folder/album/track_file>" "<my_sorted_folder/album/my_music_file">')
to place the music file in the created folder

Unfortunately, windows cmd does not consider the special char (like é ç à...) and the command fails. From what I understood, the coding of lua is a kind of UTF8.
however, CMD uses ANSI... so, I am lost.

I have tried to insert chcp commands :
os.execute ('chcp 858 && cmd copy /B /Y /V "<my_unsorted_folder/album/track_file>" "<my_sorted_folder/album/my_music_file">')
but without success...

Cano anyone knows ?
(note, I cannot use powershell)

Kind regards
MissKa

Re: cannot copy file with special char in windows

Posted: 06 Jul 2018 17:24
by ale5000
I haven't tried but maybe this:

Code: Select all

os.execute ('chcp 65001 > nul && cmd /u /c "your_command" > log.txt')
If you don't want log then this:

Code: Select all

os.execute ('chcp 65001 > nul && cmd /u /c "your_command" > nul')

Re: cannot copy file with special char in windows

Posted: 07 Jul 2018 16:11
by Misska
hello,
thank you for your support. I just tried... but it does not work.
here is the part of the code :
part3=string.format('copy /B /Y /V "%s" "%s"', filename, FinalFullPath .. file)
os.execute ('chcp 65001 > nul && cmd /u /c "' .. part3 .. '" > log.txt')
debug_trace(string.format("[Sorting...] +----> (win) " .. part3))
The debug_trace is archiving the message in a file. It shows the good path :
[Sorting...] +----> (win) copy /B /Y /V "K:\Musicologie\music_a_trier\L\La Haine\La Haine\04 La 25ème Image.m4a" "K:\Musicologie\Mytune\41_hiphop_rap_MC\L\La Haine\La Haine\04 La 25ème Image.m4a"
and the log.txt contains:
"Le fichier spécifié est introuvable" ; which means " the requested file cannot be found"

I can copy this "K:\Musicologie\music_a_trier\L\La Haine\La Haine\04 La 25ème Image.m4a" to the cmd and press enter, then it is executed. I really do not understand.

Re: cannot copy file with special char in windows

Posted: 08 Jul 2018 23:06
by roland1
It depends, but maybe vlc.io

Input/Output
------------
All path for this namespace are expected to be passed as UTF8 strings.

io.mkdir("path", "mode"): Similar to mkdir(2). The mode is passed as a string
to allow for octal representations. This returns a success code (non 0 in
case of failure), and a more specific error code as its 2nd returned value
in case of failure. The error code is to be used with vlc.errno
io.readdir("path"): Lists all files & directories in the provided folder.
io.open("path"[, "mode"]): Similar to lua's io.open. Mode is optional and
defaults to "r". It returns a file object with the following member functions:
.read
.write
.seek
.flush
.close
all of which are used exactly like the lua object returned by io.open
io.unlink("path"): Similar to os.remove. First return value is 0 in case
of success. In case of failure, the 2nd return parameter is an error
code to be compared against vlc.errno values.

Re: cannot copy file with special char in windows

Posted: 11 Jul 2018 09:52
by Jean-Baptiste Kempf
but there is no io.copy.

Re: cannot copy file with special char in windows

Posted: 11 Jul 2018 19:59
by Misska
It depends, but maybe vlc.io

Input/Output
------------
All path for this namespace are expected to be passed as UTF8 strings.

io.mkdir("path", "mode"): Similar to mkdir(2). The mode is passed as a string
to allow for octal representations. This returns a success code (non 0 in
case of failure), and a more specific error code as its 2nd returned value
in case of failure. The error code is to be used with vlc.errno
io.readdir("path"): Lists all files & directories in the provided folder.
io.open("path"[, "mode"]): Similar to lua's io.open. Mode is optional and
defaults to "r". It returns a file object with the following member functions:
.read
.write
.seek
.flush
.close
all of which are used exactly like the lua object returned by io.open
io.unlink("path"): Similar to os.remove. First return value is 0 in case
of success. In case of failure, the 2nd return parameter is an error
code to be compared against vlc.errno values.
unfortunately, even if I can locate the files, I cannot copy.
I have to use a os.execute with cmd (but if you know another way ?)

Re: cannot copy file with special char in windows

Posted: 11 Jul 2018 20:15
by roland1
but there is no io.copy.
true.
Untested:

Code: Select all

copy = function(from, to) local io = vlc.io or io local ff, err = io.open(from, "rb") if not ff then return nil, err end local ft, err = io.open(to, "wb") if not ft then return ft, err end local sz = 2^16 repeat local s = ff:read(sz) until not (s and ft:write(s)) ff:close() ft:close() return true end
unfortunately, even if I can locate the files, I cannot copy.
I have to use a os.execute with cmd (but if you know another way ?)
To help further I need code.