troubleshooting Question

removing redundant path segment(s)

Avatar of Mutley2003
Mutley2003 asked on
Delphi
5 Comments1 Solution211 ViewsLast Modified:
By redundant, I mean it contains no files and only a single subdir.

c:\
|_ temp7000
    |_ Tom
    |   |_empty
    |      |_Dick
    |         |_harry
    |         |_tom
    |_ Bill
    |   |_fred


So, if "empty" has no files (and only Dick as a folderchild)  it could be considered redundant, and after removal of "empty"  all the lower level dirstructure and the files would be preserved, so it looks like so

c:\
|_ temp7000
    |_ Tom
    |     |_Dick
    |        |_harry
    |        |_tom
    |_ Bill
    |   |_fred


What if there is more than one empty path segment? How could we remove them all in one fell swoop?

c:\
|_ temp7000
    |_ Tom
    |   |_empty
    |      |_Dick
    |         |_harry
    |         |  |_empty2
    |         |     |_camille
    |         |_tom
    |_ Bill
    |   |_fred

so that hasRedundantSubdirs('c:\temp7000')  would return true as would
 hasRedundantSubdirs('c:\temp7000\Tom') but not hasRedundantSubdirs('c:\temp7000\Tom\empty\Dick\harry\empty2')

and CleanRedundantSubdirs(('c:\temp7000')  would change the filesystem to look like

c:\
|_ temp7000
    |_ Tom
    |     |_Dick
    |        |_harry
    |        |  |_camille
    |        |_tom
    |_ Bill
    |   |_fred

It might be better, or equally useful, to do it bottom up
eg

killIrrelevantAndUselessParents('c:\temp7000\Tom\empty\Dick\harry\empty2\camille')

which no doubt many children would like to do <g>


I don't particularly like the arcane shFileOperation (I just found out today that FOF_NORECURSION is not even defined in D5, who knows why not), but if that is the elegant and safe way to do it, OK.


thanks, gurus



ASKER CERTIFIED SOLUTION
Russell Libby
Software Engineer, Advisory
Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros