@@ -254,16 +254,19 @@ function splitpath(p::String)
254
254
return out
255
255
end
256
256
257
- joinpath (path:: AbstractString ):: String = path
258
-
259
257
if Sys. iswindows ()
260
258
261
- function joinpath (path:: AbstractString , paths:: AbstractString... ):: String
262
- result_drive, result_path = splitdrive (path)
259
+ function joinpath (paths:: Union{Tuple, AbstractVector} ):: String
260
+ assertstring (x) = x isa AbstractString || throw (ArgumentError (" path component is not a string: $(repr (x)) " ))
261
+
262
+ isempty (paths) && throw (ArgumentError (" collection of path components must be non-empty" ))
263
+ assertstring (paths[1 ])
264
+ result_drive, result_path = splitdrive (paths[1 ])
263
265
264
- local p_drive, p_path
265
- for p in paths
266
- p_drive, p_path = splitdrive (p)
266
+ p_path = " "
267
+ for i in firstindex (paths)+ 1 : lastindex (paths)
268
+ assertstring (paths[i])
269
+ p_drive, p_path = splitdrive (paths[i])
267
270
268
271
if startswith (p_path, (' \\ ' , ' /' ))
269
272
# second path is absolute
299
302
300
303
else
301
304
302
- function joinpath (path:: AbstractString , paths:: AbstractString... ):: String
303
- for p in paths
305
+ function joinpath (paths:: Union{Tuple, AbstractVector} ):: String
306
+ assertstring (x) = x isa AbstractString || throw (ArgumentError (" path component is not a string: $(repr (x)) " ))
307
+
308
+ isempty (paths) && throw (ArgumentError (" collection of path components must be non-empty" ))
309
+ assertstring (paths[1 ])
310
+ path = paths[1 ]
311
+ for i in firstindex (paths)+ 1 : lastindex (paths)
312
+ p = paths[i]
313
+ assertstring (p)
304
314
if isabspath (p)
305
315
path = p
306
316
elseif isempty (path) || path[end ] == ' /'
314
324
315
325
end # os-test
316
326
327
+ joinpath (paths:: AbstractString... ):: String = joinpath (paths)
328
+
317
329
"""
318
330
joinpath(parts::AbstractString...) -> String
331
+ joinpath(parts::Vector{AbstractString}) -> String
332
+ joinpath(parts::Tuple{AbstractString}) -> String
319
333
320
334
Join path components into a full path. If some argument is an absolute path or
321
335
(on Windows) has a drive specification that doesn't match the drive computed for
@@ -331,6 +345,11 @@ letter casing, hence `joinpath("C:\\A","c:b") = "C:\\A\\b"`.
331
345
julia> joinpath("/home/myuser", "example.jl")
332
346
"/home/myuser/example.jl"
333
347
```
348
+
349
+ ```jldoctest
350
+ julia> joinpath(["/home/myuser", "example.jl"])
351
+ "/home/myuser/example.jl"
352
+ ```
334
353
"""
335
354
joinpath
336
355
0 commit comments