Login or Sign Up to become a member!
LessThanDot Site Logo

LessThanDot

A Technical Community for IT Professionals

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.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot facebook Lessthandot rss

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

Highly Rated Users

Forum
No Posts Rated

Top 50
Given
Received

Forum Statistics

Users
Members:
1535
Members Online:
3
Guests Online:
1

Total Post History
Posts:
80269
Topics:
18350

7-Day Post History
New Posts:
6
New Topics:
0
Active Topics:
3

Our newest member
vivekshah

Other

FAQ
All times are UTC [ DST ]

Google Ads

LTD Puzzle 6: split a filepath

Mind Boggling Puzzles, to keep that grey matter in shape...
Forum rules
Always post answers in a "Hidecode" tag, so that others have a chance to answer the question too.
Please wait...

LTD Puzzle 6: split a filepath

Postby chrissie1 on Fri Jul 11, 2008 8:47 am

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):

ExtensionNameOfFileTotalPathNumberOfFolders
jpgoneC:\data\old\2
jpgoneC:\data\old\2
wavthreeC:\data\new\newer\3
mp3GloriaC:\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:
  1. DECLARE @bla TABLE (tmp VARCHAR(500))
  2.  
  3. INSERT @bla VALUES( 'C:\data\old\one.jpg')
  4. INSERT @bla VALUES( 'C:\data\old\one.two.jpg')
  5. INSERT @bla VALUES( 'C:\data\new\newer\three.wav')
  6. 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
User avatar
chrissie1
Senior Guru
Senior Guru
LTD Gold - Rating: 2088LTD Gold - Rating: 2088LTD Gold - Rating: 2088LTD Gold - Rating: 2088LTD Gold - Rating: 2088
LTD Gold - Rating: 2088LTD Gold - Rating: 2088LTD Gold - Rating: 2088LTD Gold - Rating: 2088LTD Gold - Rating: 2088
LTD Gold - Rating: 2088LTD Gold - Rating: 2088
 
Posts: 9340
Joined: Wed Oct 10, 2007 7:18 pm
Location: Belgium
Unrated

Re: LTD Puzzle 6: split a filepath

Postby ca8msm on Fri Jul 11, 2008 9:39 am

Here's a VB.NET version. Just create a form and drop a DataGridView on it to see the results.
Code is hidden, SHOW

Output:
FilePathSplit.JPG
You do not have the required permissions to view the files attached to this post.
User avatar
ca8msm
LTD Admin
LTD Admin
LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687
LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687
 
Posts: 2492
Joined: Wed Oct 10, 2007 6:49 pm
Location: North East England

Re: LTD Puzzle 6: split a filepath

Postby Remou on Fri Jul 11, 2008 9:59 am

A jam and sardine sandwich, with VBA topping.

Code is hidden, SHOW


Oops.
Puzzle.PNG
You do not have the required permissions to view the files attached to this post.
Stop quoting laws to us. We carry swords.
User avatar
Remou
LTD Admin
LTD Admin
LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948
LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948
LTD Gold - Rating: 948
 
Posts: 5279
Joined: Sun Oct 14, 2007 11:26 am

Re: LTD Puzzle 6: split a filepath

Postby spoulson on Fri Jul 11, 2008 1:18 pm

Don't forget to use hidecode tags!
User avatar
spoulson
Senior Apprentice
Senior Apprentice
LTD Bronze - Rating: 115LTD Bronze - Rating: 115LTD Bronze - Rating: 115
 
Posts: 205
Joined: Mon Jun 02, 2008 2:37 am
Location: Middletown, DE, USA

Re: LTD Puzzle 6: split a filepath

Postby chrissie1 on Fri Jul 11, 2008 1:46 pm

Don't forget to use hidecode tags!


done
pink fuzzy slippers
User avatar
chrissie1
Senior Guru
Senior Guru
LTD Gold - Rating: 2088LTD Gold - Rating: 2088LTD Gold - Rating: 2088LTD Gold - Rating: 2088LTD Gold - Rating: 2088
LTD Gold - Rating: 2088LTD Gold - Rating: 2088LTD Gold - Rating: 2088LTD Gold - Rating: 2088LTD Gold - Rating: 2088
LTD Gold - Rating: 2088LTD Gold - Rating: 2088
 
Posts: 9340
Joined: Wed Oct 10, 2007 7:18 pm
Location: Belgium
Unrated

Re: LTD Puzzle 6: split a filepath

Postby SQLDenis on Fri Jul 11, 2008 1:46 pm

SQL Server version

Code is hidden, SHOW
User avatar
SQLDenis
LTD Admin
LTD Admin
LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451
LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451
LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451
 
Posts: 21665
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

Postby spoulson on Fri Jul 11, 2008 1:50 pm

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.

Code is hidden, SHOW


  1. C:\>perl p6.pl
  2. NameOfFile  Extension   Folders  TotalPath
  3. one         jpg         2        C:\data\old\one.jpg
  4. one.two     jpg         2        C:\data\old\one.two.jpg
  5. three       wmv         3        C:\data\new\newer\three.wmv
  6. Gloria      mp3         4        C:\Documents and Settings\My Music\Amazon MP3\T
  7. he Doors\Gloria.mp3
Last edited by spoulson on Fri Jul 11, 2008 2:13 pm, edited 1 time in total.
User avatar
spoulson
Senior Apprentice
Senior Apprentice
LTD Bronze - Rating: 115LTD Bronze - Rating: 115LTD Bronze - Rating: 115
 
Posts: 205
Joined: Mon Jun 02, 2008 2:37 am
Location: Middletown, DE, USA

Re: LTD Puzzle 6: split a filepath

Postby SQLDenis on Fri Jul 11, 2008 1:53 pm

poulson one of your extensions is wrong :-)
I did that on purpose of course to make it a little harder
User avatar
SQLDenis
LTD Admin
LTD Admin
LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451
LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451
LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451
 
Posts: 21665
Joined: Wed Oct 10, 2007 6:43 pm
Location: Princeton, New Jersey, USA,World, Solar System, Milky Way, Universe and Beyond
Unrated

Re: LTD Puzzle 6: split a filepath

Postby ca8msm on Fri Jul 11, 2008 2:00 pm

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".
User avatar
ca8msm
LTD Admin
LTD Admin
LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687
LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687
 
Posts: 2492
Joined: Wed Oct 10, 2007 6:49 pm
Location: North East England
Unrated

Re: LTD Puzzle 6: split a filepath

Postby SQLDenis on Fri Jul 11, 2008 2:09 pm

You have never gotten a .vbs file in the email?

virus.txt.vbs
User avatar
SQLDenis
LTD Admin
LTD Admin
LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451
LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451
LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451
 
Posts: 21665
Joined: Wed Oct 10, 2007 6:43 pm
Location: Princeton, New Jersey, USA,World, Solar System, Milky Way, Universe and Beyond
Unrated

Re: LTD Puzzle 6: split a filepath

Postby Remou on Fri Jul 11, 2008 2:19 pm

chrissie1 wrote:
Don't forget to use hidecode tags!


done


Oops and thanks.
Stop quoting laws to us. We carry swords.
User avatar
Remou
LTD Admin
LTD Admin
LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948
LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948
LTD Gold - Rating: 948
 
Posts: 5279
Joined: Sun Oct 14, 2007 11:26 am
Unrated

Re: LTD Puzzle 6: split a filepath

Postby ca8msm on Fri Jul 11, 2008 2:25 pm

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.
User avatar
ca8msm
LTD Admin
LTD Admin
LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687
LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687LTD Silver - Rating: 687
 
Posts: 2492
Joined: Wed Oct 10, 2007 6:49 pm
Location: North East England
Unrated

Re: LTD Puzzle 6: split a filepath

Postby Remou on Fri Jul 11, 2008 2:36 pm

I would also consider one.two to be the file name, but it did make it a little more difficult as Denis said.
Stop quoting laws to us. We carry swords.
User avatar
Remou
LTD Admin
LTD Admin
LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948
LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948
LTD Gold - Rating: 948
 
Posts: 5279
Joined: Sun Oct 14, 2007 11:26 am
Unrated

Re: LTD Puzzle 6: split a filepath

Postby AlexCuse on Fri Jul 11, 2008 2:37 pm

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
Say what you like about the tenets of National Socialism Dude, at least it's an ethos
User avatar
AlexCuse
LTD Admin
LTD Admin
LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021
LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021
LTD Gold - Rating: 1021
 
Posts: 5405
Joined: Tue Oct 09, 2007 5:26 pm
Location: Pennsylvania, US
Unrated

Re: LTD Puzzle 6: split a filepath

Postby SQLDenis on Fri Jul 11, 2008 2:59 pm

I depends if you have hide extensions or not :-)

either way the output has to match the requirements of the puzzle
User avatar
SQLDenis
LTD Admin
LTD Admin
LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451
LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451
LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451
 
Posts: 21665
Joined: Wed Oct 10, 2007 6:43 pm
Location: Princeton, New Jersey, USA,World, Solar System, Milky Way, Universe and Beyond
Unrated

Re: LTD Puzzle 6: split a filepath

Postby AlexCuse on Fri Jul 11, 2008 4:48 pm

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
User avatar
AlexCuse
LTD Admin
LTD Admin
LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021
LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021
LTD Gold - Rating: 1021
 
Posts: 5405
Joined: Tue Oct 09, 2007 5:26 pm
Location: Pennsylvania, US

Re: LTD Puzzle 6: split a filepath

Postby Emtucifor on Sat Jul 12, 2008 1:07 am

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:

ExtensionNameOfFileTotalPathNumberOfFolders
jpgoneC:\data\old\2
jpgone.twoC:\data\old\2
wavthreeC:\data\new\newer\3
mp3GloriaC:\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:

  1. 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.
User avatar
Emtucifor
Guru
Guru
LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030
LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030
LTD Gold - Rating: 1030
 
Posts: 2835
Joined: Fri May 30, 2008 9:30 pm
Location: Bellingham, WA

Re: LTD Puzzle 6: split a filepath

Postby Emtucifor on Sat Jul 12, 2008 1:09 am

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.
God cries a little bit every time someone builds a database.
User avatar
Emtucifor
Guru
Guru
LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030
LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030
LTD Gold - Rating: 1030
 
Posts: 2835
Joined: Fri May 30, 2008 9:30 pm
Location: Bellingham, WA
Unrated

Re: LTD Puzzle 6: split a filepath

Postby SQLDenis on Sat Jul 12, 2008 1:26 am

Erik, I did that with the file name so that it is a little (just) harder
User avatar
SQLDenis
LTD Admin
LTD Admin
LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451
LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451
LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451
 
Posts: 21665
Joined: Wed Oct 10, 2007 6:43 pm
Location: Princeton, New Jersey, USA,World, Solar System, Milky Way, Universe and Beyond
Unrated

Re: LTD Puzzle 6: split a filepath

Postby Remou on Sat Jul 12, 2008 1:36 am

Stop quoting laws to us. We carry swords.
User avatar
Remou
LTD Admin
LTD Admin
LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948
LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948LTD Gold - Rating: 948
LTD Gold - Rating: 948
 
Posts: 5279
Joined: Sun Oct 14, 2007 11:26 am
Unrated

Re: LTD Puzzle 6: split a filepath

Postby cbetancourt on Sat Jul 12, 2008 1:43 am

A JavaScript solution is here: http://claude.betancourt.us/split-filepath.html.
User avatar
cbetancourt
Apprentice
Apprentice
LTD Bronze - Rating: 69LTD Bronze - Rating: 69
 
Posts: 19
Joined: Thu Jun 05, 2008 8:35 pm
Location: Pennsylvania

Re: LTD Puzzle 6: split a filepath

Postby AlexCuse on Sat Jul 12, 2008 1:59 am

For Erik, in the page load of a .aspx page (have to add System.Collections.Generic + the list declaration from above):

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
User avatar
AlexCuse
LTD Admin
LTD Admin
LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021
LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021
LTD Gold - Rating: 1021
 
Posts: 5405
Joined: Tue Oct 09, 2007 5:26 pm
Location: Pennsylvania, US

Re: LTD Puzzle 6: split a filepath

Postby SQLDenis on Sat Jul 12, 2008 2:30 am

I would have expected Claude to use ExtJS or ColdFusion <vbg>
User avatar
SQLDenis
LTD Admin
LTD Admin
LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451
LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451
LTD Gold - Rating: 3451LTD Gold - Rating: 3451LTD Gold - Rating: 3451
 
Posts: 21665
Joined: Wed Oct 10, 2007 6:43 pm
Location: Princeton, New Jersey, USA,World, Solar System, Milky Way, Universe and Beyond
Unrated

Re: LTD Puzzle 6: split a filepath

Postby Emtucifor on Sat Jul 12, 2008 3:03 am

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! :-p :) :)
God cries a little bit every time someone builds a database.
User avatar
Emtucifor
Guru
Guru
LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030
LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030
LTD Gold - Rating: 1030
 
Posts: 2835
Joined: Fri May 30, 2008 9:30 pm
Location: Bellingham, WA
Unrated

Re: LTD Puzzle 6: split a filepath

Postby ilitirit on Wed Jul 16, 2008 3:36 pm

Using built-in methods
Code is hidden, SHOW
ilitirit
Newbie
Newbie
LTD Bronze - Rating: 4
 
Posts: 2
Joined: Tue Jun 10, 2008 6:29 pm

Next