# How to join file paths

**URL:** https://clojureverse.org/t/how-to-join-file-paths/814
**Category:** How to?
**Tags:** clojure
**Created:** [November 15, 2017, 9:04pm UTC](https://clojureverse.org/t/how-to-join-file-paths/814 "2017-11-15T21:04:17Z")
**Posts on this page:** 1
**Showing post:** 12

<div class="post-metadata">

### Author: ![linpengcheng](https://clojureverse.org/user_avatar/clojureverse.org/linpengcheng/32/296_2.png) [@linpengcheng](https://clojureverse.org/u/linpengcheng)
#### Post date: [November 17, 2017, 1:42am UTC](https://clojureverse.org/t/how-to-join-file-paths/814/12 "2017-11-17T01:42:19Z")

</div>

@plexus:

This pure clojure function satisfies your needs:

```clojure
(defn path-combine [s1 s2]
  (cond
    (string/starts-with? s2 "/") 
      s2
    (not (string/ends-with? s1 "/"))
      (-> (string/split s1 #"[\\/]")
          butlast
          (#(string/join "/" %))
          (str , "/")
          (path-combine , s2)) 
    :else  
      (-> (string/join "/" [s1 s2])
          (string/replace , #"[\\/]+" "/")))) 

```

---

_[View the full topic](https://clojureverse.org/t/how-to-join-file-paths/814)._
