{"id":549,"date":"2005-06-17T18:05:48","date_gmt":"2005-06-17T22:05:48","guid":{"rendered":"http:\/\/www.starkeith.net\/coredump\/?p=549"},"modified":"2009-04-12T20:34:31","modified_gmt":"2009-04-13T00:34:31","slug":"folder-parsing","status":"publish","type":"post","link":"https:\/\/www.starkeith.net\/coredump\/2005\/06\/17\/folder-parsing\/","title":{"rendered":"Folder Parsing"},"content":{"rendered":"<p>I think I&#8217;ll talk about Work today.<\/p>\n<p>Let&#8217;s consider the current problem I&#8217;m facing. First, imagine that you&#8217;ve got a folder hierarchy set up, with files stored in only the &#8220;bottom&#8221; folders. Thus, a typical folder path might look something like this:<\/p>\n<p><code>C:\\Main Category\\Sub Category\\Individual Section\\File Name.doc<\/code><\/p>\n<p>Just for fun, let&#8217;s say that those are all the folders &#8211; that is to say, any file will always be in 3 folders deep. Here&#8217;s the trick, though: you want to programatically examine the &#8220;Individual Section&#8221; folder name for any given file. For the sake of argument, let&#8217;s say you want to do this because you only want to affect files in one particular &#8220;Individual Section.&#8221; <\/p>\n<p>Oh, and just to make it more specific, let&#8217;s remember that we&#8217;re doing this in Visual Basic 6.0.<\/p>\n<p>So, how do we find the &#8220;Individual Section?&#8221; Here&#8217;s what I&#8217;m thinking currently: the file path comes to you as a string, of course, so we can do fun <code>Instr<\/code> and <code>Instrrev<\/code> searches on it. Looking at the path, we can say that the &#8220;Individual Section&#8221; will always be between the first and second backslashes (&#8220;&#8221;), as if you start at the end of the string. (Or, to put it another way, it&#8217;ll always be between the 2nd to last and last backslash in the string.)<\/p>\n<p>So here&#8217;s what I came up with (I used &#8220;firstSlash&#8221; and &#8220;secondSlash&#8221; because they are easier to type than &#8220;2ndToLastSlash,&#8221; if you follow me):<\/p>\n<p><code>Dim tmpStr As String<br \/>\nDim firstSlash As Integer<br \/>\nDim secondSlash As Integer<\/code><\/p>\n<p><code>tmpStr = \"C:\\Main Category\\Sub Category\\Individual Section\\Document Name.doc\"<\/code><\/p>\n<p><code>firstSlash = InStrRev(tmpStr, \"\")<br \/>\nsecondSlash = InStrRev(tmpStr, \"\", firstSlash - 1)<\/code><\/p>\n<p><code>debug.print Mid(tmpStr, secondSlash + 1, (firstSlash - secondSlash) - 1)<\/code><\/p>\n<p>We need a -1 in the line to find the secondSlash because we don&#8217;t want to include the first slash in our search. Similarly, we have to add +1 to secondSlash, and -1 to the length when we use the MID function to chop off those nasty backslashes (we use them for positioning, but we don&#8217;t want them in our output).<\/p>\n<p>Not very exciting, I know, but hey &#8211; this is what I do all day. And before I started this post, I didn&#8217;t have the specific algorithm done &#8211; and now I do. So yay for me!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Some musing on a technical folder parsing problem I was working on (do you understand recursion?).<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"webmentions_disabled_pings":false,"webmentions_disabled":false,"_jetpack_memberships_contains_paid_content":false,"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":3,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":""},"categories":[5],"tags":[],"class_list":["post-549","post","type-post","status-publish","format-standard","hentry","category-technology","entry"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pimUj-8R","jetpack-related-posts":[{"id":2557,"url":"https:\/\/www.starkeith.net\/coredump\/2009\/05\/18\/how-to-move-your-windows-user-profile-to-another-drive\/","url_meta":{"origin":549,"position":0},"title":"How to Move your Windows User Profile to another Drive (Updated)","author":"Keith Survell","date":"May 18, 2009","format":false,"excerpt":"How to seamlessly move (or redirect) your entire Windows user profile to a different drive (or location) using NTFS junction points instead of other, less elegant methods.","rel":"","context":"In &quot;Software&quot;","block_context":{"text":"Software","link":"https:\/\/www.starkeith.net\/coredump\/category\/technology\/software-technology\/"},"img":{"alt_text":"My \"Videos\" library, located on a different drive","src":"https:\/\/i0.wp.com\/www.starkeith.net\/coredump\/wp-content\/uploads\/\/2009\/05\/libraries.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":5909,"url":"https:\/\/www.starkeith.net\/coredump\/2022\/11\/21\/22h2-windows-11-as-it-should-have-been\/","url_meta":{"origin":549,"position":1},"title":"22H2 &#8211; Windows 11 as it should have been","author":"Keith Survell","date":"November 21, 2022","format":false,"excerpt":"So the latest Windows 11 update - 22H2 - got rolled out to my desktop PC recently and I've finally had a chance to try it out and form an opinion on it. To me, this update feels like what Windows 11 should have been from the start. It fixes\u2026","rel":"","context":"In &quot;My Opinion&quot;","block_context":{"text":"My Opinion","link":"https:\/\/www.starkeith.net\/coredump\/category\/personal\/my-opinion\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.starkeith.net\/coredump\/wp-content\/uploads\/\/2022\/11\/windows-specifications.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.starkeith.net\/coredump\/wp-content\/uploads\/\/2022\/11\/windows-specifications.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.starkeith.net\/coredump\/wp-content\/uploads\/\/2022\/11\/windows-specifications.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.starkeith.net\/coredump\/wp-content\/uploads\/\/2022\/11\/windows-specifications.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":1874,"url":"https:\/\/www.starkeith.net\/coredump\/2009\/03\/21\/computer-recovery-day\/","url_meta":{"origin":549,"position":2},"title":"Computer Recovery Day","author":"Keith Survell","date":"March 21, 2009","format":false,"excerpt":"An agonizing tale of computer malfunction, data recovery, and pain.","rel":"","context":"In &quot;My Life&quot;","block_context":{"text":"My Life","link":"https:\/\/www.starkeith.net\/coredump\/category\/personal\/my-life\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1114,"url":"https:\/\/www.starkeith.net\/coredump\/2008\/05\/14\/really-annoying-flaw-in-ntfs-mount-points\/","url_meta":{"origin":549,"position":3},"title":"Really Annoying Flaw in NTFS Mount Points","author":"Keith Survell","date":"May 14, 2008","format":false,"excerpt":"UPDATE: As some people have noted, this problem was fixed in Windows Vista, so \"it's not really a problem anymore.\" And with Windows 7 out now, and Windows XP slowly dying, there's no real reason to worry about this anymore. But I'm leaving this article here, just for the sake\u2026","rel":"","context":"In &quot;Rants&quot;","block_context":{"text":"Rants","link":"https:\/\/www.starkeith.net\/coredump\/category\/rants\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1873,"url":"https:\/\/www.starkeith.net\/coredump\/2009\/03\/17\/i-upgraded-to-vista-but-for-all-the-wrong-reasons\/","url_meta":{"origin":549,"position":4},"title":"I Upgraded to Vista &ndash; But for all the Wrong Reasons","author":"Keith Survell","date":"March 17, 2009","format":false,"excerpt":"Even though I swore I wouldn\u2019t upgrade to Vista, just recently I bit the bullet and did it anyway. But I did it for all the wrong reasons.","rel":"","context":"In &quot;My Life&quot;","block_context":{"text":"My Life","link":"https:\/\/www.starkeith.net\/coredump\/category\/personal\/my-life\/"},"img":{"alt_text":"vista","src":"https:\/\/i0.wp.com\/www.starkeith.net\/coredump\/wp-content\/uploads\/\/2009\/03\/vista-thumb.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":1094,"url":"https:\/\/www.starkeith.net\/coredump\/2008\/05\/01\/a-computer-conundrum\/","url_meta":{"origin":549,"position":5},"title":"A Computer Conundrum","author":"Keith Survell","date":"May 1, 2008","format":false,"excerpt":"Once again, I've filled up my hard drive. It's inevitable, really - I tend to keep everything, and my music, picture, and video collections are quite... extensive. What's sad is that I bought my computer a little over a year ago, and I distinctly remember remaking that its 160 GB\u2026","rel":"","context":"In &quot;personal&quot;","block_context":{"text":"personal","link":"https:\/\/www.starkeith.net\/coredump\/category\/personal\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.starkeith.net\/coredump\/wp-json\/wp\/v2\/posts\/549","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.starkeith.net\/coredump\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.starkeith.net\/coredump\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.starkeith.net\/coredump\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.starkeith.net\/coredump\/wp-json\/wp\/v2\/comments?post=549"}],"version-history":[{"count":0,"href":"https:\/\/www.starkeith.net\/coredump\/wp-json\/wp\/v2\/posts\/549\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.starkeith.net\/coredump\/wp-json\/wp\/v2\/media?parent=549"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.starkeith.net\/coredump\/wp-json\/wp\/v2\/categories?post=549"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.starkeith.net\/coredump\/wp-json\/wp\/v2\/tags?post=549"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}