Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

File Path tracing

Posted on 2006-04-25
5
Medium Priority
?
234 Views
Last Modified: 2012-05-05
I need to be able to trace a file path back to a directory that has a certain folder or directory in it.

Example:

FilePath:
C:\temp\project\code\resources\temp.c

Path to find is
C:\temp\project\code\src\copper\....
0
Comment
Question by:tjwallace05
  • 4
5 Comments
 
LVL 24

Expert Comment

by:sciuriware
ID: 16537235
What is the relation between what you have and what to find?????

;JOOP!
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 16537286
Or maybe you mean:

File dir = new File("C:\temp\project\code\resources\temp.c").getParent();
String toFind = "........"; // Fill in.

while(!new File(dir, toFind).exists())
{
     File parent = dir.getParent();
     if(parent.getAbsolutePath().equals(dir.getAbsolutePath())
     {
          break;  // Not found.
     }
     dir = parent;
}
// Found in 'dir'.

;JOOP!
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 16537298
Again a type, correction:

File dir = new File("C:\temp\project\code\resources\temp.c").getParentFile();
String toFind = "........"; // Fill in.

while(!new File(dir, toFind).exists())
{
     File parent = dir.getParentFile();
     if(parent.getAbsolutePath().equals(dir.getAbsolutePath())
     {
          break;  // Not found.
     }
     dir = parent;
}
// Found in 'dir'.

;JOOP!
0
 
LVL 24

Accepted Solution

by:
sciuriware earned 375 total points
ID: 16537308
And the break better be a throw Exception or a return.

;JOOP!
0
 

Author Comment

by:tjwallace05
ID: 16537620
The link is to find the directory with the folder "src".  I need to backup the pathname until the directory contains the "src" folder.  Then I would like to trace that directory until I hit a certain folder "faults".
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month11 days, 18 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question