Scolring - Forum

Entraides et échanges autour de la technologie Scol - Informations and exchanges on the Scol technology

Vous pouvez changer la langue de l'interface une fois inscrit - You can change the language once registered

You are not logged in.

#1 31-Oct-2014 19:38:09

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,477
Website

extracting last 2 directories from a url

Colleagues:

How would I use the core or os3d api to take:

 [url]http://ifam.net/openspace/hybridui3/mainwindow/mainwindow.pak[/url] mainwindow/mainwindow.pak

And return:

mainwindow/mainwindow.pak

You can tell me where to look in the tools directories and I should be able to figure it out
Thx

Offline

#2 31-Oct-2014 20:06:33

arkeon
Admin. / Scol language & OpenSpace3D developer
From: Nantes
Registered: 30-Mar-2009
Posts: 4,821
Website

Re: extracting last 2 directories from a url

there is tools for this in tools.pkg
getlastPathDir

Offline

#3 31-Oct-2014 20:10:21

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,477
Website

Re: extracting last 2 directories from a url

arkeon wrote:

there is tools for this in tools.pkg
getlastPathDir


Thx I'll get to work with that.

Offline

#4 31-Oct-2014 20:53:22

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,477
Website

Re: extracting last 2 directories from a url

how to get the last two directories as a string from a url:

  let "http://ifam.net/openspace/spacemanshooter17/dan_no_mohawk/spacemanshooter1.pak" -> urlsrc in	
  let getlastPathDir urlsrc -> destpathfile in
  let getFilePathWithoutExt destpathfile -> download_directory in
  let strcatn download_directory::"/"::destpathfile::nil-> destpath in

will return:

spacemanshooter/spacemanshooter1.pak

which is ok, (the file saves to cache and loads in player) although how would I get a return value of "dan_no_mohawk" from the full url?

Offline

#5 31-Oct-2014 21:17:18

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: extracting last 2 directories from a url

let "http://ifam.net/openspace/spacemanshooter17/dan_no_mohawk/spacemanshooter1.pak" -> urlsrc in
let getlastPathDir urlsrc -> destpathfile in
let getlastPathDir destpathfile -> download_directory  in
let strcatn download_directory::"/"::destpathfile::nil-> destpath in

No ?
Why you write :

let getFilePathWithoutExt destpathfile -> download_directory in

Offline

#6 31-Oct-2014 23:16:49

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,477
Website

Re: extracting last 2 directories from a url

Its my ignorant attempts to get second to last directory..

Offline

#7 31-Oct-2014 23:22:28

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: extracting last 2 directories from a url

getFilePathWithoutExt gets the file name without its extension.
By example
"getFilePathWithoutExt spacemanshooter1.pak" returns "spacemanshooter1"

Offline

#8 1-Nov-2014 00:34:44

arkeon
Admin. / Scol language & OpenSpace3D developer
From: Nantes
Registered: 30-Mar-2009
Posts: 4,821
Website

Re: extracting last 2 directories from a url

let strToListSep path "/" -< l in
let nth_list l (sizelist l) - 2 -< dir in

Offline

#9 1-Nov-2014 03:37:13

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,477
Website

Re: extracting last 2 directories from a url

arkeon wrote:

let strToListSep path "/" -< l in
let nth_list l (sizelist l) - 2 -< dir in

I was thinking in my uneducated mind something involving slicing up a string into a list thx.

Offline

#10 2-Nov-2014 17:47:54

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,477
Website

Re: extracting last 2 directories from a url

thx arkeon

for the scol overmind

how to use core api/os3d string tools to get the name of a file, preceded by a forward slash, preceded by the next higher directory

full url: "http://ifam.net/openspace/spacemanshoot … ooter1.pak"
string we want to use as path to save file in cache:   "dan_no_mohawk/spacemanshooter1.pak"

  getUrlContentLenght "http://ifam.net/openspace/spacemanshooter17/dan_no_mohawk/spacemanshooter1.pak" @cbGetContentLength;	
  let "http://ifam.net/openspace/spacemanshooter17/dan_no_mohawk/spacemanshooter1.pak" -> urlsrc in	
 //get the name of the file,  this is the 'lastpath'.  
  let getlastPathDir urlsrc -> destpathfile in
  //split string into list of strings s r1, each of which is before, between, or after a "/"
  let strToListSep urlsrc "/" -> urlist in
  //get the second to last string, which is the folder in which the file is found
  let nth_list urlist (sizelist urlist) - 2 ->secontolastdir in
  //put file's folder  together with / with file name 
  let strcatn secontolastdir::"/"::destpathfile::nil-> destpath in

this code produces the string: "dan_no_mohawk/spacemanshooter1.pak", which is the same string as lastpath, along with the name of the directory holding it.

Offline

Board footer

Powered by FluxBB