10 Replies Latest reply: Nov 24, 2010 4:08 PM by 818066 RSS

    Hiding System files in Windows

    818066
      I've noticed that JFileChooser hides Windows System files. Files like hiberfil.sys, pagefile.sys, $Recycle.Bin, a number of shortcut folders that you can't open, etc...

      I could hide .sys files but that would only hide a few of them (and not the folders).

      I'm guessing it’s a hidden sun only method but I would like to know, so at least on Oracle Java it will look right.

      Note: system files are not hidden files, so hiding hidden files will not work.

      Sum up: How to figure out what is a system files/folders using Java.



      Edited by: 815063 on Nov 23, 2010 2:31 PM
        • 1. Re: Hiding System files in Windows
          EJP
          attrib +s filename                                                                                                                                                                                                                                               
          • 2. Re: Hiding System files in Windows
            818066
            Woops I updated my post I mean I want to figure out what is a system file/folder so then I can hide it from the jtable.
            • 3. Re: Hiding System files in Windows
              EJP
              You can't tell whether a file is a system file from within Java until JDK 1.7.
              • 4. Re: Hiding System files in Windows
                818066
                EJP wrote:
                You can't tell whether a file is a system file from within Java until JDK 1.7.
                How does JFileChooser does it then? I tried looking through the source code, but couldn't find it. I thought it might be something in sun.awt.shell.ShellFolder but couldn't see anything.
                • 5. Re: Hiding System files in Windows
                  EJP
                  It must have some native code somewhere.
                  • 6. Re: Hiding System files in Windows
                    818066
                    Either way, I'm hoping someone knows how its done :)
                    • 7. Re: Hiding System files in Windows
                      EJP
                      There's no other way it could be done. There's nothing in the Java API, so it must have some JNI code somewhere. QED.
                      • 8. Re: Hiding System files in Windows
                        818066
                        I tried digging into the source code again to figure out how. I believe it loads it files by BasicDirectoryModel class:
                         public void run0() {
                                    FileSystemView fileSystem = filechooser.getFileSystemView();
                        
                                    File[] list = fileSystem.getFiles(currentDirectory, filechooser.isFileHidingEnabled());
                        
                                    if (isInterrupted()) {
                                        return;
                                    }
                        
                                    final Vector newFileCache = new Vector();
                                    Vector newFiles = new Vector();
                        
                                    // run through the file list, add directories and selectable files to fileCache
                                    // Note that this block must be OUTSIDE of Invoker thread because of
                                    // deadlock possibility with custom synchronized FileSystemView
                                    for (File file : list) {
                                        if (filechooser.accept(file)) {
                                            boolean isTraversable = filechooser.isTraversable(file);
                        
                                            if (isTraversable) {
                                                newFileCache.addElement(file);
                                            } else if (filechooser.isFileSelectionEnabled()) {
                                                newFiles.addElement(file);
                                            }
                        
                                            if (isInterrupted()) {
                                                return;
                                            }
                                        }
                                    }
                        ....
                         
                        But nothing special in grabbing the files. The "accept()" method doesn't do it. I also changed the filter to use accept all files and that didn't change anything.
                        So maybe my quest has come to a dead end, unless a Java Engineer that has worked around this area might know how...
                        • 9. Re: Hiding System files in Windows
                          818066
                          Found it! It was totally simple.

                          I didn't check fileSystem.getFiles vs file.listFiles as I thought someone here would of told me that.

                          It seems fileSystem.getFiles is what I want to look into. Going to dig into it and see if I can find any method that checks if its a system file.

                          Edit:
                          I don't need to check what is a system file if its already hidden :)

                          There might be a way to check but the code gets a little tricky to understand in Win32ShellFolder2.

                          Thanks everyone for the help.

                          Edited by: Zammbi on Nov 24, 2010 1:43 PM
                          • 10. Re: Hiding System files in Windows
                            818066
                            Answer Summary:

                            fileSystem.getFiles method returns a list of files which are not System files.

                            Note: There is no List() filename method that does the same.