Skip to content
Latchkey

How to Handle Path Separators in Windows Scripts in GitHub Actions

Windows accepts forward slashes in most tools, so use them for paths that must also work on Linux.

Most cross-platform tools and PowerShell accept / on Windows, so prefer forward slashes. When a native command needs backslashes, branch on runner.os.

Steps

  • Use forward slashes in paths handled by node, python, git, and PowerShell.
  • Branch on ${{ runner.os }} when a step truly needs OS-specific separators.
  • Reference ${{ github.workspace }} rather than hardcoding a drive path.

Workflow

.github/workflows/ci.yml
jobs:
  build:
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v4
      - name: Forward slashes work on Windows
        shell: pwsh
        run: Get-Content "src/config/app.json"
      - name: OS-specific path when required
        shell: pwsh
        run: |
          if ($env:RUNNER_OS -eq "Windows") {
            & ".\tools\win\pack.exe"
          } else {
            & "./tools/linux/pack"
          }

Gotchas

  • In bash on Windows (Git Bash), backslashes are escape characters, so prefer forward slashes there.
  • Use ${{ github.workspace }} instead of C:\ paths so the workflow stays portable.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →