Menu

file deleting and process pending

Help
2011-11-01
2013-03-18
  • nenad cikic

    nenad cikic - 2011-11-01

    I am writing a simple java class for file managing and i have encountered a strange problem.
    The following method empties the folder (deletes all files of the specified extension).
    static String EmptyFolder(String foldName,final String fileExt){
        try{
           File f=new File(foldName);
         
           FilenameFilter dew = new FilenameFilter() {
              public boolean accept(File f, String name) {
                return name.toUpperCase(Locale.ENGLISH).endsWith(fileExt.toUpperCase(Locale.ENGLISH));
              }
            }; 

            File delF = f.listFiles(dew);      

            for (int i = 0; i < delF.length; i++) {
              if (!delF_.delete()){
                  return delF.getName();
              }
            }
                 
            return "true";
        }      

        catch(Exception e){
            System.out.println (e);

            return "false";
        }
    }

    When i put the code in a test.java and run it from console it deletes the specific files. If i use it from c2j it fails on file.delete. There is no exception:the return delF.getName(); gets executed with the correct name. Obviously the file is not read only as the test.java successfully deletes it.
    I have check the net and it seems that there is some java bug with file.delete, but all the people had problems when deleting after reading/copying/moving the same file.
    While i was trying to solve the problem i noticed that when i exit my c2j application there is a javaw process pending in task manager. When i start from console there is java process pending, and when i hit Ctrl+C the process exits. The same is behaving your cookbook example. Remember i am using clarion6, and also i am using the last postgresql. Have you seen these problems?

    Thanks
    Nenad_

     
  • nenad cikic

    nenad cikic - 2011-11-02

    I have managed to solve file deletion problem. It seem that when deleting i have to specify the file name with path (although the example i copied from internet did not do it this way). The following works:
            for (int i = 0; i < delF.length; i++) {
              tempF=new File(foldName.trim() + "/" + delF_.getName());
              if (!tempF.delete()){
                  QiqoFolders.lastErrStr="Neuspješno brisanje " + tempF.getName();
                  return false;
              }
            } 

    While debugging I came though to the following problem. This is my clarion code:
    FolderName           STRING(20) 
    isOK bool
    errStr string(200)
    code
      FolderName='Cust_' & CU:id !where cu:id is long
    compile('java-end',java)
         @java-code 'isOK.setValue(QiqoFolders.EmptyFolder(folderName.toString(),".qik"));'
    java-end

    When i stamp the foldName + "/" + delF.getName() inside the EmptyFolder i get something as "Cust_1 /aa.qik" i.e. i have one empty space at the end foldName. And thats why i do trim.
    So my question is now: isn't this a bug that the toString method of ClaString returns one empty space at the end? Or it is the string concatenation that adds one space at the end?

    I have still to investigate the pending process error.
    Thanks
    Nenad_

     
  • Andrew Barnham

    Andrew Barnham - 2011-11-02

    The additional space is because foldName is 20 char string.  Clarion strings are fixed width and padded. And c2j replicates this behaviour precisely; even for toString() method (many things in ABC for example rely on this behaviour).  Try using CSTRING or PSTRING instead.

    c2j introduces a language 'extension'.  If you don't define a string size, i.e. this:
    FolderName STRING

    c2j will make it a variable length string without a size limit that is not padded (unless you explicitly add spaces to the end of the string).  Keep in mind that these do not work very well with clarion OVER() attribute for example, because the 'memory' footprint a variable string occupies is not well defined.

     
  • nenad cikic

    nenad cikic - 2011-11-02

    OK, understood
    thanks
    Nenad

     

Log in to post a comment.

Auth0 Logo