1

I'm trying to create a tarball of a directory using tar.exe on Windows 11. When I run in PowerShell or cmd:

tar -c -f file.tar directory\

I get the error

tar.exe: OCESSORS=24: Couldn't visit directory: No such file or directory

The name of the directory it couldn't visit varies between runs, but it seems to always grab some portion of an environment variable (e.g. env.PATH, etc), sometimes with the name of the directory stuck to the end of it.

It seems to work if I omit the trailing backslash:

tar -c -f file.tar directory

but I'm wondering what the issue is, particularly since PowerShell autocompletion adds the trailing backslash to the directory. I've read that trailing backslashes can cause issues in PowerShell but doesn't seem to apply in this situation since there are no special characters in the directory name, and in any case I don't see how it's grabbing a part of a random environment variable when it runs.

1 Answers1

1

PowerShell is just the messenger here (you'd see the same problem in a cmd.exe session, for instance):

Unlike Unix implementations, the Windows tar implementation, tar.exe seemingly doesn't permit an optional trailing path separator, even when targeting a directory (neither \ nor / is accepted).

However, at least with version bsdtar 3.5.2 (as reported by tar --version and as found on Windows 11 22H2), this seems to be a cosmetic problem only:

  • Despite the error messages, the command works.

This unfortunately clashes with PowerShell's tab-completion, which invariably appends a path separator on completing a directory name.
The solution is to simply remove it manually, after completion.


Separately, in Windows PowerShell only (since fixed in PowerShell (Core) 7+), a trailing \ causes problems in arguments with spaces when calling any external program:

mklement0
  • 382,024
  • 64
  • 607
  • 775