View Full Version : Issue with FILE_kill
Hello
I encounter a problem with File_Kill function.
The part of code I encounter the problem :
function clean_dir
nFiles = DIR_ListArray(MyList, ".", "*", %FILE_NORMAL + %FILE_ADDPATH)
printl " nombre de fichier(s) trouve(s) " , nFiles in c_green
for ii = 1 to nFiles
print mylist(ii) , " " in c_magenta
printl file_kill(mylist(ii) )
Next
end function
This code works correctly with most files, but fails with filename containing accented letters, some are from files transferred fro MAC.
With unaccented files the retcode is 0 and the file is removed. :D
With accented files the retcode is 53 = File not found and obviously the file is NOT removed. :mad:
I suppose that is as the issue I posted 29-01-2024, 19:35 , Eros replyed 14-02-2023, 12:09 about ANSI/OEM/UTF8 conversion ?
Another little flaw with File_Kill
If the file name to remove is a subdir, the subdir is not removed, normal it is designed for files.....
But the return code is 0, which means : No error ...
Maybe , would it be someting as 75 = Wrong path ?
Regards,
Dany
ReneMiner
22-11-2024, 07:52
The accented-non-accented thing appears to me as a problem of the codepage more than a thinbasic problem
we will find out,
open windows explorer, where you can type the path, type %COMSPEC% [enter]
the windows console will open,into console window type CHCP[enter]
you will be informed about the currently used codepage, ANSI i guess 850 or 1252 (latin or western europe) if french speaking
Now thinbasic default works unicode-aware using UTF8 which is a codepage number 65001
%CP_utf7 = 65000
%CP_utf8= 65001
%CP_utf16_LE = 1200 ' this is the WIDECHAR 16 bit on windows
%CP_utf16_BE = 1201 ' UNIX,Linux,Solarix,Androidix, Macintoshix,ComputerLäuftNix,..
ANSI/OEM/EBCDIC/BOCU/SCSU are a couple of codepage-collections mostly deprecated
When you are working with a visible console window, i.e. your code contains
Uses "console"
then it were applicable to let
Console_SetoutputCP( %CP_UTF8 )
' Console_SetInputCP( %CP_UTF8 ) might set this to the number <XXX>
Console_ShowWindow( %Console_SW_SHOWNORMAL )
and it should go conform with content of thuinbasic UTF8-encoded strings.
When no visible console window either you use
string FileToRun = App_Scriptpath & "myBatchfile.bat"
string FileResult= App_Scriptpath & "reply.txt"
String myBatchfile ="@echo off" & $CRLF & "chcp >" & FileResult & $crlf & $spc
File_Save(FileToRun, myBatchfile)
Shell FileToRun, "", True
msgbox "Returned was " & File_load(FileResult)
' .bat-scripts are usually ANSI. if your batchfile contains accented chars or the result is unreadable convert
myBatchfile=utf8ToAnsi$(myBatchfile)
before saving it and vice versa
msgbox "Returned was " & AnsiToUtf8$(File_load(FileResult))
Shell_CaptureOutput can do this without the files on a more direct way since thinbasic takes care of incoming data to be UTF8 (at least i hope so)
Begin Const
$_CMD= "%COMSPEC% /C "
End Const
string sAll = Shell_captureOutput( $_CMD & "Dir /a:-d /b" ,"", %SW_HIDE, 20)
string sCurrDir = Shell_CaptureOutput( $_CMD & "CD", "",%SW_HIDE,10)
msgbox "Found Files" & $crlf & sAll, %mb_iconInformation, sCurrDir
String sFile()
Long numFiles = parse sAll, sFile, $CRLF
' will make an array of all files in sAll
string isTB = Shell_CaptureOutput( $_CMD & "IF EXIST " & $DQ & App_Path & "thinbasic.exe" & $DQ & " (ECHO TRUE) ELSE (ECHO FALSE)", "", %SW_HIDE,10)
msgbox App_Path & "thinbasic.exe EXIST = " & isTB
'The parenthesis surrounding ECHO TRUE and ECHO FALSE prevent from additional whitespace that might follow after "FALSE" so it will not return is as "FALSE "
' For directories the path must end with backslash when EXIST is used
gives you an idea.
Of course you can combine batchfiles and result-files with the direct-method , just for a reminder
Echo Hello>myFile.txt
Echo World >>myFile.txt
the single "arrow >" ovewrites the content of an existing file
and double "arrow >>" appends it to the existing content.
Not a programmatic solution were to lauch cmd,
click on the icon(system-menu) upper left corner and
check settings,
then the rightmost tab should also tell the current by the system used codepage that i would try as number <XXX> mentioned above
The accented-non-accented thing appears to me as a problem of the codepage more than a thinbasic problem
we will find out,
open windows explorer, where you can type the path, type %COMSPEC% [enter]
the windows console will open,into console window type CHCP[enter]
you will be informed about the currently used codepage, ANSI i guess 850 or 1252 (latin or western europe) if french speaking
Now thinbasic default works unicode-aware using UTF8 which is a codepage number 65001
[code]
%CP_utf7 = 65000
%CP_utf8= 65001
%CP_utf16_LE = 1200 ' this is the WIDECHAR 16 bit on windows
%CP_utf16_BE = 1201 ' UNIX,Linux,Solarix,Androidix, Macintoshix,ComputerLäuftNix,..
Hello Rene,
I'm perfectly aware of code pages.
The post is to point that two functions of ThinBasic, used in the same script, in the same sub, don't agree with code pages.
Someware, the same kind of problem was pointed to, and Eros corrected the flaw.
Echo Hello>myFile.txt
Echo World >>myFile.txt
the single "arrow >" ovewrites the content of an existing file
and double "arrow >>" appends it to the existing content.
Thanks for the explain of redirections. As you can read in my profile, I was Unix sys-admin for 20 years ;)
Dany.
ErosOlmi
23-11-2024, 09:59
Hello
I encounter a problem with File_Kill function.
The part of code I encounter the problem :
function clean_dir
nFiles = DIR_ListArray(MyList, ".", "*", %FILE_NORMAL + %FILE_ADDPATH)
printl " nombre de fichier(s) trouve(s) " , nFiles in c_green
for ii = 1 to nFiles
print mylist(ii) , " " in c_magenta
printl file_kill(mylist(ii) )
Next
end function
This code works correctly with most files, but fails with filename containing accented letters, some are from files transferred fro MAC.
With unaccented files the retcode is 0 and the file is removed. :D
With accented files the retcode is 53 = File not found and obviously the file is NOT removed. :mad:
I suppose that is as the issue I posted 29-01-2024, 19:35 , Eros replyed 14-02-2023, 12:09 about ANSI/OEM/UTF8 conversion ?
Another little flaw with File_Kill
If the file name to remove is a subdir, the subdir is not removed, normal it is designed for files.....
But the return code is 0, which means : No error ...
Maybe , would it be someting as 75 = Wrong path ?
Regards,
Dany
Hi Dany, can you please attach a file (even empty file) with the name creating problems in File_Kill?
I'm trying to reproduce the problem on my computer but File_Kill seems working fine with accented chars like èùàòéì.
So I think I'm missing something
Petr Schreiber
28-11-2024, 20:41
Hi Dany,
tried it on my PC and also could not get the files to remain undeleted.
If you can pack a directory with the offending files, it would help greatly!
Petr