Absolute paths on Windows do not work #40

Closed
goloroden opened this Issue Apr 16, 2012 · 5 comments

6 participants

@goloroden

Steps to repro:

  • Create a folder C:\test
  • Put some *.txt files in there
  • Try to get them using glob.sync('/test/*.txt')

Note:

  • All backslashes were correctly replaced by forward-slashes

Expected result:

  • An array with a list of files of the folder C:\test

Actual result:

PS:

  • It works using relative paths, it's only absolute paths that seem to be broken
@joewhite

When I try this, I do get results, although they're a bit odd.

> glob.sync('/temp/*.txt')
[ '\\temp/1.txt' ]

The initial / is unexpectedly replaced with a \, but I do get results. Using glob@3.1.9 with Node v0.6.12 on Windows 7 64-bit.

@unknownbrackets

The issue here is that this line:

read = prefix = path.join("/", prefix)

On windows turns into:

read = prefix = "\"

Which it then prepends onto things here:

if (prefix !== "/") e = prefix + "/" + e

The same line is causing issues for drive letters in issue 42.

-[Unknown]

@springmeyer

I just hit this as well. I worked around it by passing in the absolute path for the cwd option, and then a relative path for the actual search term.

@kylealanhale

I had thought this was a minimatch problem, so I left a comment there outlining the inconsistencies: isaacs/minimatch#11 (comment).

For now I am doing pretty much what @springmeyer suggested, with a normalization step following to clean up the weird path separators.

@isaacs
Owner

Fixed in the latest release.

@isaacs isaacs closed this Jan 23, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment