Go-ipfs: WISH: Add built-in globbing on Windows

Created on 22 May 2016  路  8Comments  路  Source: ipfs/go-ipfs

On Windows 7 Ultimate 64-bit with NTFS, ipfs add gives an error when trying to add files using wildcard / globbing, e.g. ipfs add * and ipfs add *.txt.

Example

c:\tmp> echo Hello > hello.txt
c:\tmp> ipfs add *
Error: GetFileAttributesEx *: The filename, directory name, or volume label syntax is incorrect.
[...]

c:\tmp> ipfs add *.txt
Error: GetFileAttributesEx *.txt: The filename, directory name, or volume label syntax is incorrect.
[...]

c:\tmp> ipfs add .*.txt
Error: GetFileAttributesEx .*.txt: The filename, directory name, or volume label syntax is incorrect.
[...]

c:\tmp> ipfs version
ipfs version 0.4.2

c:\tmp> dir *
 Volume in drive C is Windows7_OS
 Volume Serial Number is ****-****

 Directory of C:\tmp

05/22/2016  09:53 AM    <DIR>          .
05/22/2016  09:53 AM    <DIR>          ..
05/22/2016  09:53 AM                 8 hello.txt
               1 File(s)              8 bytes
               2 Dir(s)   1,989,726,208 bytes free

It works when specifying the complete filename:

c:\tmp> ipfs add hello.txt
8 B / 8 B [========================================================] 100.00 % 0
added QmSpPJmG5quyMoZDmZv9npYabmKBjkXS6Mfo2tQuz2UYP1 hello.txt

This works on Linux, e.g.

$ echo Hello > hello.txt
$ ipfs add *
added QmY9cxiHqTFoWamkQVkpmmqzBrY3hCBEL2XNu3NtX74Fuu hello.txt
$ ipfs version
ipfs version 0.4.2
help wanted kinenhancement neecommunity-input topiwindows

Most helpful comment

Under the assumption that all other shells do globbing for IPFS, would it make sense to only call Glob() on Windows? For instance, I'm pretty sure Windows will throw an exception if you try to create / write a file with name *.txt (not just from the shell).

All 8 comments

It is because AFAIK Windows doesn't support globbing.

I believe Windows's cmd.exe supports globbing, e.g.

Z:\home\JohnDoe>dir *.txt    
Volume in drive Z has no label.
Volume Serial Number is 0000-0000

Directory of Z:\home\JohnDoe

 6/10/2016   7:14 PM           156  NOTES.txt
       JohnDoe1 file                       156 bytes
       0 directories    435,023,372,288 bytes free

or are you saying that the shell itself does not pass the expanded *.txt (as multiple arguments) to the executable called?

Yes that I what I am saying.

I see. So, I guess this issue now turned into a feature request asking for built-in support for globbing by ipfs. I'm _not_ a golang user / develop so in case I have very little to contribute. Maybe,

func Glob(pattern string) (matches []string, err error)

of filepath is of use here?

@HenrikBengtsson i think that does do what you want. We could probably detect glob characters in the input and call that on it if found.

That sounds great. (I'm becoming almost a full-time *nix user these days, but figured there are/will be lots on IPFS users on Windows too).

@whyrusleeping problem is that glob characters can be valid filenames, we could make heuristic that if there is no file like that we try to expand the globe.

Under the assumption that all other shells do globbing for IPFS, would it make sense to only call Glob() on Windows? For instance, I'm pretty sure Windows will throw an exception if you try to create / write a file with name *.txt (not just from the shell).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kallisti5 picture kallisti5  路  3Comments

JesseWeinstein picture JesseWeinstein  路  4Comments

jonchoi picture jonchoi  路  3Comments

daviddias picture daviddias  路  3Comments

whyrusleeping picture whyrusleeping  路  4Comments