7 Replies Latest reply: Sep 5, 2007 10:11 AM by 807605 RSS

    File Finding on Unix plateform

    807605
      hey, I have a quick question when your doing a recursive file search/scan whatever, on unix/linux you have can symbolic links that can potentially point back to the parent directory or multiple directories above the immediate parent directory. Java interprets these links as folders, whats the best way to prevent infinite loops when scanning for a file on a unix platform. essentially, how do you determine a link from a folder in java? any really simple way?

      Thanks in advance
        • 1. Re: File Finding on Unix plateform
          807605
          You can get the canonical file using method File.getCanonicalFile(). This will be the File you have linked to, not the link. If they are the same ....

          It has always bugged me that there is no method File.isSymbolicLink() .
          • 2. Re: File Finding on Unix plateform
            807605
            It has always bugged me that there is no method File.isSymbolicLink() .
            Maybe because symlinks are not supported on every platform.
            There is no isResourceFork() method either...
            • 3. Re: File Finding on Unix plateform
              807605
              It has always bugged me that there is no method
              File.isSymbolicLink() .

              Maybe because symlinks are not supported on every
              platform.
              There is no isResourceFork() method either...
              If there are no symlinks supported for a particular platform then the method should always return false!
              • 4. Re: File Finding on Unix plateform
                807605
                If there are no symlinks supported for a particular platform then the method should always return false!
                Likewise the isResourceFork() should return false if the given platform (and/or file system) does not support resource forks - whatever they might be in other platforms.

                And isShortcut() should return false if the given platform does not support Shortcuts.

                And isUnixDomainSocket() should return false if the given platform does not support Unix Domain Sockets.

                And isNamedPIpe() should return false if the given platform (and/or file system) does not support named pipes (fifos).

                And isMessageQueue() should return false if the given platform does not support message queues or if it supports them but not though file names.

                And isCatalog() should return false if the given platform does not work with the catalog/member paradigm.

                And isSequentialFile() should return false if the given platform does not support the notion of sequential files but considers the files a a stream of bytes as modern OS'es do. (In good old mainframe days, sequential and index-sequential files were supported by the OS.)

                ...etc...
                • 5. Re: File Finding on Unix plateform
                  807605
                  ...etc...
                  :-) Point taken! <stamps-foot>But I still want an 'is' method for symbolic links! </stamps-foot>

                  P.S. I'm very glad I no longer have to worry about sequential and indexed files.
                  • 6. Re: File Finding on Unix plateform
                    807605
                    I must admit: if I could, I would vote for the inclusion of isSymlink()...
                    • 7. Re: File Finding on Unix plateform
                      807605
                      Or you can rather retrieve data from ls -l and find out if the given file is a symbolic file or not. Symbolic link files would have 'l' as a prefix to the permissions for that file.