- asL = Split("C:\data\old\one.jpg|" _
- & "C:\data\old\one.two.jpg|" _
- & "C:\data\new\newer\three.wav|" _
- & "C:\Documents and Settings\My Music\Amazon MP3\The Doors\Gloria.mp3", "|")
- Set fs = CreateObject("Scripting.FileSystemObject")
- For i = 0 To UBound(asL)
- sdat = sdat & "<tr><td>" & fs.GetExtensionName(asL(i)) & "</td>" _
- & "<td>" & Mid(fs.GetBaseName(asL(i)), 1, InStr(fs.GetBaseName(asL(i)) & ".", ".") - 1) & "</td>" _
- & "<td>" & fs.GetParentFolderName(asL(i)) & "</td>" _
- & "<td>" & Len(asL(i)) - Len(Replace(asL(i), "\", "")) - 1 & "</td></tr>"
- Next
- Set f = fs.CreateTextFile("C:\docs\out.html", True)
- f.Write ("<html><table><tr><td>Extension</td><td>NameOfFile</td><td>TotalPath</td><td>NumberOfFolders</td></tr>" _
- & sdat & "</table></html>")
- FollowHyperlink "C:\docs\out.html"
Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.
Forum Search
Forum Statistics
UsersTotal Post History
- Posts:
- 78544
- Topics:
- 17949
7-Day Post History
- New Posts:
- 47
- New Topics:
- 22
- Active Topics:
- 25
Our newest member
Other
-
FAQ
All times are UTC [ DST ]
Google Ads
LTD Puzzle 6: split a filepath
Forum rules
Always post answers in a "Hidecode" tag, so that others have a chance to answer the question too.
Always post answers in a "Hidecode" tag, so that others have a chance to answer the question too.
41 posts • Page 1 of 2 • 1, 2
Please wait...
LTD Puzzle 6: split a filepath
This puzzle is not very complicated 
Let's say you have the following 4 items:
C:\data\old\one.jpg
C:\data\old\one.two.jpg
C:\data\new\newer\three.wav
C:\Documents and Settings\My Music\Amazon MP3\The Doors\Gloria.mp3
You have to split this data and also show how many folders are in the path.
The output has to be like this (including the names):
Take a look at the 2nd item (C:\data\old\one.two.jpg), in this case one is still the filename and jpg is the extension (this really has 2 extensions but we only want to see jpg).
Write the shortest code possible, creating the array or table does not count towards the total characters of the code.
So if you do this first:
Or create and fill in an array (Java, VB, C#, Ruby etc etc), do not count that part.
Good luck !

Let's say you have the following 4 items:
C:\data\old\one.jpg
C:\data\old\one.two.jpg
C:\data\new\newer\three.wav
C:\Documents and Settings\My Music\Amazon MP3\The Doors\Gloria.mp3
You have to split this data and also show how many folders are in the path.
The output has to be like this (including the names):
| Extension | NameOfFile | TotalPath | NumberOfFolders |
| jpg | one | C:\data\old\ | 2 |
| jpg | one | C:\data\old\ | 2 |
| wav | three | C:\data\new\newer\ | 3 |
| mp3 | Gloria | C:\Documents and Settings\My Music\Amazon MP3\The Doors\ | 4 |
Take a look at the 2nd item (C:\data\old\one.two.jpg), in this case one is still the filename and jpg is the extension (this really has 2 extensions but we only want to see jpg).
Write the shortest code possible, creating the array or table does not count towards the total characters of the code.
So if you do this first:
- DECLARE @bla TABLE (tmp VARCHAR(500))
- INSERT @bla VALUES( 'C:\data\old\one.jpg')
- INSERT @bla VALUES( 'C:\data\old\one.two.jpg')
- INSERT @bla VALUES( 'C:\data\new\newer\three.wav')
- INSERT @bla VALUES( 'C:\Documents and Settings\My Music\Amazon MP3\The Doors\Gloria.mp3')
Or create and fill in an array (Java, VB, C#, Ruby etc etc), do not count that part.
Good luck !
pink fuzzy slippers
-

chrissie1 - Senior Guru

-











- Posts: 9106
- Joined: Wed Oct 10, 2007 7:18 pm
- Location: Belgium
Re: LTD Puzzle 6: split a filepath
Here's a VB.NET version. Just create a form and drop a DataGridView on it to see the results.
Output:
Code is hidden, SHOW
Output:
You do not have the required permissions to view the files attached to this post.
-

ca8msm - LTD Admin

-









- Posts: 2492
- Joined: Wed Oct 10, 2007 6:49 pm
- Location: North East England
Re: LTD Puzzle 6: split a filepath
You do not have the required permissions to view the files attached to this post.
x
-

Remou - LTD Admin

-










- Posts: 5115
- Joined: Sun Oct 14, 2007 11:26 am
Re: LTD Puzzle 6: split a filepath
Don't forget to use hidecode tags!
-

spoulson - Senior Apprentice

-


- Posts: 205
- Joined: Mon Jun 02, 2008 2:37 am
- Location: Middletown, DE, USA
-

chrissie1 - Senior Guru

-











- Posts: 9106
- Joined: Wed Oct 10, 2007 7:18 pm
- Location: Belgium
-

SQLDenis - LTD Admin

-












- Posts: 21304
- Joined: Wed Oct 10, 2007 6:43 pm
- Location: Princeton, New Jersey, USA,World, Solar System, Milky Way, Universe and Beyond
Re: LTD Puzzle 6: split a filepath
Since this is a golf competition, I naturally solved this in Perl as a one-liner. Hopefully, it's not too cryptic. I commented it to explain what is going on.
Note, I disagree that "one.two.jpg" has two extensions. Multiple periods in a filename delimit more than just extensions. For example, in the unix world I often see files and folders with dot-delimited versions, datetime stamps, etc. So, I coded with the assumption that "one.two" is the filename portion.
Note, I disagree that "one.two.jpg" has two extensions. Multiple periods in a filename delimit more than just extensions. For example, in the unix world I often see files and folders with dot-delimited versions, datetime stamps, etc. So, I coded with the assumption that "one.two" is the filename portion.
Code is hidden, SHOW
- C:\>perl p6.pl
- NameOfFile Extension Folders TotalPath
- one jpg 2 C:\data\old\one.jpg
- one.two jpg 2 C:\data\old\one.two.jpg
- three wmv 3 C:\data\new\newer\three.wmv
- Gloria mp3 4 C:\Documents and Settings\My Music\Amazon MP3\T
- he Doors\Gloria.mp3
Last edited by spoulson on Fri Jul 11, 2008 2:13 pm, edited 1 time in total.
-

spoulson - Senior Apprentice

-


- Posts: 205
- Joined: Mon Jun 02, 2008 2:37 am
- Location: Middletown, DE, USA
Re: LTD Puzzle 6: split a filepath
poulson one of your extensions is wrong 
I did that on purpose of course to make it a little harder

I did that on purpose of course to make it a little harder
-

SQLDenis - LTD Admin

-












- Posts: 21304
- Joined: Wed Oct 10, 2007 6:43 pm
- Location: Princeton, New Jersey, USA,World, Solar System, Milky Way, Universe and Beyond
Re: LTD Puzzle 6: split a filepath
Denis,
In that case mine is wrong too. However, I'm with spoulson; if the path is "C:\data\old\one.two.jpg" then the filename is "one.two" not "one".
In that case mine is wrong too. However, I'm with spoulson; if the path is "C:\data\old\one.two.jpg" then the filename is "one.two" not "one".
-

ca8msm - LTD Admin

-









- Posts: 2492
- Joined: Wed Oct 10, 2007 6:49 pm
- Location: North East England
Re: LTD Puzzle 6: split a filepath
You have never gotten a .vbs file in the email?
virus.txt.vbs
virus.txt.vbs
-

SQLDenis - LTD Admin

-












- Posts: 21304
- Joined: Wed Oct 10, 2007 6:43 pm
- Location: Princeton, New Jersey, USA,World, Solar System, Milky Way, Universe and Beyond
Re: LTD Puzzle 6: split a filepath
chrissie1 wrote:Don't forget to use hidecode tags!
done
Oops and thanks.
x
-

Remou - LTD Admin

-










- Posts: 5115
- Joined: Sun Oct 14, 2007 11:26 am
Re: LTD Puzzle 6: split a filepath
Yes, and I still think the same. In the case of the .vbs file, it is just a file named "virus.txt" with a .vbs extension.
-

ca8msm - LTD Admin

-









- Posts: 2492
- Joined: Wed Oct 10, 2007 6:49 pm
- Location: North East England
Re: LTD Puzzle 6: split a filepath
I would also consider one.two to be the file name, but it did make it a little more difficult as Denis said.
x
-

Remou - LTD Admin

-










- Posts: 5115
- Joined: Sun Oct 14, 2007 11:26 am
Re: LTD Puzzle 6: split a filepath
I too think the last extension is the only extension.
Otherwise I'd probably die when I see a filename like this: II.II407.DVDAFUL.FLAT.G0139V00
Otherwise I'd probably die when I see a filename like this: II.II407.DVDAFUL.FLAT.G0139V00
Say what you like about the tenets of National Socialism Dude, at least it's an ethos
-

AlexCuse - LTD Admin

-










- Posts: 5263
- Joined: Tue Oct 09, 2007 5:26 pm
- Location: Pennsylvania, US
Re: LTD Puzzle 6: split a filepath
I depends if you have hide extensions or not 
either way the output has to match the requirements of the puzzle

either way the output has to match the requirements of the puzzle
-

SQLDenis - LTD Admin

-












- Posts: 21304
- Joined: Wed Oct 10, 2007 6:43 pm
- Location: Princeton, New Jersey, USA,World, Solar System, Milky Way, Universe and Beyond
Re: LTD Puzzle 6: split a filepath
this ought to be close enough (for the console). I tried to do it with only string manipulation functions, none of the luxuries (well, except for Linq and anonymous types
)
)Code is hidden, SHOW
Say what you like about the tenets of National Socialism Dude, at least it's an ethos
-

AlexCuse - LTD Admin

-










- Posts: 5263
- Joined: Tue Oct 09, 2007 5:26 pm
- Location: Pennsylvania, US
Re: LTD Puzzle 6: split a filepath
Code is hidden, SHOW
Note: because the bbcode parser is messing up my code, I had to replace [ with {. Reverse this to get running code.
Sample output:
| Extension | NameOfFile | TotalPath | NumberOfFolders |
| jpg | one | C:\data\old\ | 2 |
| jpg | one.two | C:\data\old\ | 2 |
| wav | three | C:\data\new\newer\ | 3 |
| mp3 | Gloria | C:\Documents and Settings\My Music\Amazon MP3\The Doors\ | 4 |
And as others have said, there is a mistake in the name of the file in the second row in the original post. Not only is this a puzzle but it relates to things in the real world. Ask MS Windows what the file name is of "one.two.jpg" and it will tell you "one.two".
To see this in action, open a command window and run the following command:
- echo.>one.two.jpg&for %e in (one.two.jpg) do @echo filename portion of one.two.jpg is "%~ne"&del one.two.jpg<nul
Last edited by Emtucifor on Sat Jul 12, 2008 1:12 am, edited 1 time in total.
God cries a little bit every time someone builds a database.
-

Emtucifor - Guru

-










- Posts: 2832
- Joined: Fri May 30, 2008 9:30 pm
- Location: California
Re: LTD Puzzle 6: split a filepath
I would like to vote that output which isn't aligned with labels at the top doesn't meet the conditions of the challenge. 
If it does, then I would like to submit a new version.

If it does, then I would like to submit a new version.
God cries a little bit every time someone builds a database.
-

Emtucifor - Guru

-










- Posts: 2832
- Joined: Fri May 30, 2008 9:30 pm
- Location: California
Re: LTD Puzzle 6: split a filepath
Erik, I did that with the file name so that it is a little (just) harder
-

SQLDenis - LTD Admin

-












- Posts: 21304
- Joined: Wed Oct 10, 2007 6:43 pm
- Location: Princeton, New Jersey, USA,World, Solar System, Milky Way, Universe and Beyond
-

Remou - LTD Admin

-










- Posts: 5115
- Joined: Sun Oct 14, 2007 11:26 am
Re: LTD Puzzle 6: split a filepath
A JavaScript solution is here: http://claude.betancourt.us/split-filepath.html.
-

cbetancourt - Apprentice

-

- Posts: 19
- Joined: Thu Jun 05, 2008 8:35 pm
- Location: Pennsylvania
Re: LTD Puzzle 6: split a filepath
For Erik, in the page load of a .aspx page (have to add System.Collections.Generic + the list declaration from above):
I like that one Claude
Code is hidden, SHOW
I like that one Claude
Say what you like about the tenets of National Socialism Dude, at least it's an ethos
-

AlexCuse - LTD Admin

-










- Posts: 5263
- Joined: Tue Oct 09, 2007 5:26 pm
- Location: Pennsylvania, US
Re: LTD Puzzle 6: split a filepath
I would have expected Claude to use ExtJS or ColdFusion <vbg>
-

SQLDenis - LTD Admin

-












- Posts: 21304
- Joined: Wed Oct 10, 2007 6:43 pm
- Location: Princeton, New Jersey, USA,World, Solar System, Milky Way, Universe and Beyond
Re: LTD Puzzle 6: split a filepath
SQLDenis wrote:Erik, I did that with the file name so that it is a little (just) harder
But you called it the file name which makes me constitutionally incapable of obeying. So call it something else!

God cries a little bit every time someone builds a database.
-

Emtucifor - Guru

-










- Posts: 2832
- Joined: Fri May 30, 2008 9:30 pm
- Location: California
Re: LTD Puzzle 6: split a filepath
Using built-in methods
Code is hidden, SHOW
- ilitirit
- Newbie

-
- Posts: 2
- Joined: Tue Jun 10, 2008 6:29 pm
41 posts • Page 1 of 2 • 1, 2



LTD Social Sitings
Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.