0

I have an issue where, in a recursive situation, I need the path of each file in a directory, but only from the top folder to the filename... not any system type files. Is there a way to set up an enum or "For Each" type of loop that would take off the part of the path that comes before the actual top directory of a path?

Example1: C:\Users\John\Desktop[My Files\My Subfiles\MyDocuments001.tif] where the brackets contain what I need to keep. Similarly, even in the same job, or if I browse to another directory to continue working on files there, it would do the same split regardless where the directory was on the computer:

Example2: C:\Users\John\Documents[My Other Files\My Other Subfiles\MyOtherDocuments001.tif]

This is in VB.net 2010.

Any ideas?

2
Contributors
1
Reply
2
Views
4 Years
Discussion Span
Last Post by Reverend Jim
0

Since you know the starting folder, you could get the path to the parent folder and save it in a string (let's call it rootparent). Then when you get the full path and file name in the for loop you could do

mypath = fullpath.Replace(rootparent,"")

or

mypath = fullpath.Replace(rootparent,"..")

depending on whether you want your files to display as

\My Files\My Subfiles\MyDocuments001.tif

or

..\My Files\My Subfiles\MyDocuments001.tif
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.