Back to main page
 


- Presentation of Rebol
- Script examples
- dir-tree.r
 clean-path.r
- Rebol Site Builder Manual

Back

Last updated on 30-Aug-2001.

compteur visitors.

Printing logoFor printing.

 
   
       clean-path.r

Version française

REBOL [
	Title: "my clean path"
	Date: 1999-11-19
	File: %clean-path.r
	Author: "Stephane Bagnier"
	Organization: "D2SET french association"
	Web-Site: http://www.multimania.com/d2set/
	Email: bagnier@physique.ens.fr
	Version: 1.0
	Tabs: 4
	Need: 2.2
	Purpose: {
    	Cleans-up '.' and '..' in path; returns the cleaned path.
    	This script is smaller than the original, and works on an url !
	}
]

clean-path: func [
    {Cleans-up '.' and '..' in path; returns the cleaned path} 
    target [file! url!] 
    /local target-copy detail clean-target][
    target-copy: copy target
    if all [file? target-copy (first target-copy) <> #"/"] [
        insert target-copy system/script/path]
    detail: parse/all (to-string target-copy) "/"
    until [error? try [remove find detail "."]]
    until [error? try [remove/part back find detail ".." 2]]
    clean-target: either file? target [to-file head detail
    ][  remove back tail first detail
        to-url (head remove next head detail)]
    if (last target) == #"/" [append clean-target #"/"]
    clean-target
]

; trial

	to-clean-list:[
	%toto/./tata/./dummy/../titi
	%toto/./tata/dummy/dummy2/../../titi
	%toto/./tata/dummy/../titi/
	%/toto/./tata/dummy/../titi
	file://toto/./tata/dummy/../titi
	http://www.rebol.com/toto/./ta%20ta/dummy/../titi
	file://toto/./tata/dummy/../titi/
	http://www.rebol.com/toto/./tata/dummy/../titi/]

	foreach thing to-clean-list [
    	print reduce [thing "^(tab)->^(tab)" mold clean-path thing]
	]


 
 
 
http:/ / d2set.free.fr/ en/ projects/ site/ RebolSiteBuilder/ clean-path.html