Results 1 to 5 of 5

Thread: Issue with FILE_kill

  1. #1
    Member
    Join Date
    Jan 2018
    Location
    France
    Age
    72
    Posts
    74
    Rep Power
    14

    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.
    With accented files the retcode is 53 = File not found and obviously the file is NOT removed.

    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
    Last edited by dco045; 22-11-2024 at 19:56.

  2. #2
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,553
    Rep Power
    174
    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
    Last edited by ReneMiner; 22-11-2024 at 08:11.
    I think there are missing some Forum-sections as beta-testing and support

  3. #3
    Member
    Join Date
    Jan 2018
    Location
    France
    Age
    72
    Posts
    74
    Rep Power
    14
    Quote Originally Posted by ReneMiner View Post
    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.

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,816
    Rep Power
    10
    Quote Originally Posted by dco045 View Post
    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.
    With accented files the retcode is 53 = File not found and obviously the file is NOT removed.

    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
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  5. #5
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,150
    Rep Power
    736
    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
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

Similar Threads

  1. File_kill
    By cjungbauer in forum File
    Replies: 2
    Last Post: 09-11-2009, 15:00
  2. Retroaction Issue Two
    By matthew in forum Shout Box Area
    Replies: 3
    Last Post: 12-05-2009, 17:13
  3. using file_kill
    By sandyrepope in forum thinBasic General
    Replies: 9
    Last Post: 02-04-2007, 15:10
  4. PCOPY! Issue #40 Is Now Available.
    By MystikShadows in forum PCOPY!
    Replies: 7
    Last Post: 15-03-2007, 21:19

Members who have read this thread: 5

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •