How ignore a subdirectory

556 views
Skip to first unread message

John Souvestre

unread,
Sep 12, 2023, 11:48:01 PM9/12/23
to golan...@googlegroups.com

I’m trying to run gofmt on all of the .go files in a directory, but not any subdirectories.  I have tried using “.” for the target.  It does get all of the .go in the current directory, but it also does all the .go files in subdirectories.  To be more specific: There is one particular subdirectory which I don’t want it to process: “_Save”.

 

The https://pkg.go.dev/cmd/go documentation says:

 

Directory and file names that begin with "." or "_" are ignored by the go tool, as are directories named "testdata".

 

I have used this in the past and it worked fine.  But it doesn’t seem to work now.

 

Besides “_Save”, I tried “.Save” and even “testdata”.  It processed all of them.  The command I am using is “gofmt -d .”.

 

The files in the “_Save” subdirectory are not part of my program’s build, some of them are .go files.  There are no references to them in my code, however.

 

Am I misunderstanding something?  Or not doing something correctly?

 

I’m doing this on Windows 10, by the way.

 

Thanks,

 

John

 

    John Souvestre    New Orleans LA, USA    504-454-0899

 

Jan Mercl

unread,
Sep 13, 2023, 2:31:39 AM9/13/23
to John Souvestre, golan...@googlegroups.com
On Wed, Sep 13, 2023 at 5:47 AM 'John Souvestre' via golang-nuts
<golan...@googlegroups.com> wrote:

> I’m trying to run gofmt on all of the .go files in a directory, but not any subdirectories.

$ gofmt *.go

John Souvestre

unread,
Sep 13, 2023, 6:26:06 AM9/13/23
to Jan Mercl, golan...@googlegroups.com
I did try that also. I get this error message:

CreateFile *.go: The filename, directory name, or volume label syntax is incorrect.

John

John Souvestre New Orleans LA, USA 504-454-0899

Jan Mercl

unread,
Sep 13, 2023, 6:34:35 AM9/13/23
to John Souvestre, golan...@googlegroups.com
On Wed, Sep 13, 2023 at 12:25 PM John Souvestre <jo...@souvestre.com> wrote:
> I did try that also.  I get this error message:
>
>     CreateFile *.go: The filename, directory name, or volume label syntax is incorrect.

Sorry, I'm not familiar with Windows and only TIL cmd.exe does not expand globs. I suggest to install WSL and try something like

        C:\>bash -c 'gofmt *.go'

HTH

Brian Candler

unread,
Sep 13, 2023, 8:29:34 AM9/13/23
to golang-nuts
I believe that "go fmt ." (note the space after "go") works on the current package only.

Ian Lance Taylor

unread,
Sep 13, 2023, 9:45:32 AM9/13/23
to John Souvestre, golan...@googlegroups.com
On Tue, Sep 12, 2023 at 8:47 PM 'John Souvestre' via golang-nuts
<golan...@googlegroups.com> wrote:
>
> I’m trying to run gofmt on all of the .go files in a directory, but not any subdirectories. I have tried using “.” for the target. It does get all of the .go in the current directory, but it also does all the .go files in subdirectories. To be more specific: There is one particular subdirectory which I don’t want it to process: “_Save”.
>
>
>
> The https://pkg.go.dev/cmd/go documentation says:
>
>
>
> Directory and file names that begin with "." or "_" are ignored by the go tool, as are directories named "testdata".

Note that this applies to "go fmt", not "gofmt".

Ian

John Souvestre

unread,
Sep 13, 2023, 3:27:19 PM9/13/23
to golan...@googlegroups.com

What is TIL?

 

Installing WSL just to solve this seems like it might be overkill.  A for loop in a batch file, or in DOSKEY, would suffice.

 

John

 

    John Souvestre    New Orleans LA, USA    504-454-0899

 

From: Jan Mercl <0xj...@gmail.com>
Sent: 2023-09-13, Wed 05:33
To: John Souvestre <jo...@souvestre.com>
Cc: golan...@googlegroups.com
Subject: Re: [go-nuts] How ignore a subdirectory

 

On Wed, Sep 13, 2023 at 12:25 PM John Souvestre <jo...@souvestre.com> wrote:

John Souvestre

unread,
Sep 13, 2023, 3:29:32 PM9/13/23
to golang-nuts

You are correct.  However, “gofmt .” recurses.  It turns out that they handle it differently.

 

John

 

    John Souvestre    New Orleans LA, USA    504-454-0899

 

From: golan...@googlegroups.com <golan...@googlegroups.com> On Behalf Of Brian Candler
Sent: 2023-09-13, Wed 07:30
To: golang-nuts <golan...@googlegroups.com>
Subject: Re: [go-nuts] How ignore a subdirectory

 

I believe that "go fmt ." (note the space after "go") works on the current package only.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/cf14f4f9-14fa-495e-905e-d7a62d8c070dn%40googlegroups.com.

John Souvestre

unread,
Sep 13, 2023, 3:30:57 PM9/13/23
to Ian Lance Taylor, golan...@googlegroups.com
> Note that this applies to "go fmt", not "gofmt".

Ah! I didn't realize that. Yes, https://pkg.go.dev/cmd/gofmt says that it handles "." recursively.

John

John Souvestre New Orleans LA, USA 504-454-0899

-----Original Message-----
From: Ian Lance Taylor <ia...@golang.org>
Sent: 2023-09-13, Wed 08:45
To: John Souvestre <jo...@souvestre.com>
Cc: golan...@googlegroups.com
Subject: Re: [go-nuts] How ignore a subdirectory

Ian Lance Taylor

unread,
Sep 13, 2023, 3:55:15 PM9/13/23
to John Souvestre, golan...@googlegroups.com
On Wed, Sep 13, 2023 at 12:27 PM 'John Souvestre' via golang-nuts
<golan...@googlegroups.com> wrote:
>
> What is TIL?

https://knowyourmeme.com/memes/today-i-learned-til

Ian

John Souvestre

unread,
Sep 13, 2023, 4:00:16 PM9/13/23
to golan...@googlegroups.com
Ok, now I understand. I searched for computer related acronyms and only came up with Threaded Interpreted Languages. 😊

John

John Souvestre New Orleans LA, USA 504-454-0899

-----Original Message-----
From: Ian Lance Taylor <ia...@golang.org>
Sent: 2023-09-13, Wed 14:55
To: John Souvestre <jo...@souvestre.com>
Cc: golan...@googlegroups.com
Subject: Re: [go-nuts] How ignore a subdirectory

Reply all
Reply to author
Forward
0 new messages