Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: How to find all the symbolic link in a directory in windows

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    4
    My Mood
    Amazed
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation How to find all the symbolic link in a directory in windows

    I need to design a gui that will find out all the dead symbolic link from the directories. And I used the logic and syntax I find out in java orcle docs. And If I will give the direct path name of the symbolic file then it is running fine with the output and enable to find the smbolic link is active or not. Now the real problem is that , I want that logic of detection should run out through the complete files and subdirectories of the directory. So Then I used the tree walk concept to transver through the complete file system of the directory and embed the logic of the detection inside it for detection of the dead symbolic link. But now it showing erroe which is not approacable for me. I am new to java and īThis is my first project in java please help me. i will be greatful to you

    import java.io.File;
    import java.io.IOException;
    import java.io.PrintStream;
    import java.nio.file.Files;
    import java.nio.file.Path;
    import java.nio.file.Paths;
     
    public class To_Transver {
     
        public void walk( String path ) {
     
            File root = new File( path );
            File[] list = root.listFiles();
     
            if (list == null) return;
     
     for ( File f : list ) {
     Path link;
     String k
                k = f.getAbsolutePath();
        link=Paths.get(k);
     
                try {
     
            PrintStream format;
         format = System.out.format("Target of link" +
                 " '%s' is '%s'%n", link,
                 Files.readSymbolicLink(link);
      }
      catch (IOException x) {
      System.err.println(x);
      }
     
            }
        }
      public static void main(String[] args) {
            To_Transver fw = new To_Transver();
            fw.walk("C:\\" );
        }
    }

    Error:java.nio.file.FileSystemException: Incorrect function.
    Last edited by abhijava; September 30th, 2014 at 06:52 AM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,479
    Thanks
    53
    Thanked 2,406 Times in 2,359 Posts

    Default Re: How to find all the symbolic link in a directory in windows

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.

    Please copy the full text of the error message and paste it here. It has important info about the error.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    abhijava (September 30th, 2014)

  4. #3
    Member jdv's Avatar
    Join Date
    Jul 2014
    Location
    This Land
    Posts
    73
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Default Re: How to find all the symbolic link in a directory in windows

    Don't turn yourself inside-out with all this old java.io.* stuff. Look at java.nio.file.Files and (if necessary) Path interface.

    Much cleaner, much more straightforward, and much easier to make work cross-platform. (Even though you said this is for Windows, every Java program eventually wants to run somewhere else.)

  5. #4
    Junior Member
    Join Date
    Sep 2014
    Posts
    4
    My Mood
    Amazed
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How to find all the symbolic link in a directory in windows

    hello jdv

    Path link;
    String k
    k = f.getAbsolutePath();
    link=Paths.get(k);

    I think the problem is between this Paths.get () is unable to take absolute path. If I directly give link=Paths.get("C\somthing");
    then it works fine.The main problem it is not taking directly path from get.AbsolutePath();

  6. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,479
    Thanks
    53
    Thanked 2,406 Times in 2,359 Posts

    Default Re: How to find all the symbolic link in a directory in windows

    What is the value in k that is passed to the get() method? Print it to see it.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #6
    Junior Member
    Join Date
    Sep 2014
    Posts
    4
    My Mood
    Amazed
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How to find all the symbolic link in a directory in windows

    It is printing the path name of the files.. But I think the value k passing through paths.get is having some problem?
    K is printing path like c:\folder
    and if I am using direct path then paths.get() then I used to escape in path c:\\folder

    I also tried to use replaceAll for the string.

    The problem is K is string and passing through Paths.get();

  8. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,479
    Thanks
    53
    Thanked 2,406 Times in 2,359 Posts

    Default Re: How to find all the symbolic link in a directory in windows

    I used to escape in path c:\\folder
    You do not need to escape the \ if it is already in the String object. It's when the \ is used in a source statement that is read by the compiler that it needs to be escaped so the compiler knows what to do.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #8
    Junior Member
    Join Date
    Sep 2014
    Posts
    4
    My Mood
    Amazed
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How to find all the symbolic link in a directory in windows

    I am not using it , I tried using it. But the fact is the path.get is not working without escape . Thanks for your answers.
    The problem lies within this problem only , I am new to java. Please guide me. I will be grateful to you.
    k = f.getAbsolutePath();
    link=Paths.get(k);

  10. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,479
    Thanks
    53
    Thanked 2,406 Times in 2,359 Posts

    Default Re: How to find all the symbolic link in a directory in windows

    path.get is not working
    Those two statements work for me.
    Can you copy the full text of the error message and paste it here. You need to call the printStackTrace() method in the catch block to get the full text.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 3
    Last Post: April 30th, 2014, 08:03 AM
  2. Replies: 1
    Last Post: July 26th, 2013, 03:25 AM
  3. [SOLVED] Data Structures: Symbolic Algebra with Trees
    By Staticity in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 20th, 2012, 01:42 AM
  4. How to copy files from one directory to another directory
    By kewlkeny in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: January 25th, 2012, 07:36 AM
  5. where can i find the tmp/foo directory?
    By Idy in forum Java IDEs
    Replies: 11
    Last Post: January 19th, 2010, 11:21 AM

Tags for this Thread