Comparing 8.3 and long paths

Viewed 20

I have a github action that wants to test if a specific path has been created, and I'm running into a problem where github has

USERNAME=runneradmin
TMP=C:\Users\RUNNER~1\AppData\Local\Temp

The test script (VIRTUAL_ENV is set by the activate.bat script):

echo on
set "WORKON_HOME=%TMP%\wo home %RANDOM%"
mkdir "%WORKON_HOME%"
cd /d "%WORKON_HOME%"
virtualenv "name with spaces"
cd "name with spaces"
call Scripts\activate.bat

if "%WORKON_HOME%\name with spaces"=="%VIRTUAL_ENV%" (
    echo workon home and virtualenv are equal
) else (
    echo. "%WORKON_HOME%\name with spaces" is not equal to "%VIRTUAL_ENV%"
)
if "%CD%"=="%VIRTUAL_ENV%" (
    echo cd and virtualenv are equal
) else (
    echo. "%CD%" is not equal to "%VIRTUAL_ENV%"
)
exit /b 1

The output is (the difference is RUNNER~1 vs runneradmin):

 "C:\Users\RUNNER~1\AppData\Local\Temp\wo home 14549\name with spaces" is not equal to "C:\Users\runneradmin\AppData\Local\Temp\wo home 14549\name with spaces"
 "C:\Users\RUNNER~1\AppData\Local\Temp\wo home 14549\name with spaces" is not equal to "C:\Users\runneradmin\AppData\Local\Temp\wo home 14549\name with spaces"

The action yaml for completeness:

name: BUG

on: [ push, pull_request, workflow_dispatch ]

jobs:
  ci-test:
    name: BUG
    runs-on: windows-latest

    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-python@v2
        with:
          python-version: 3.9
      - run: pip install virtualenv
      - shell: cmd
        run: set
      - name: Run tests
        shell: cmd
        run: |
          tests\bug.bat

How can I make the paths compare equal?

1 Answers

I found an answer using a subroutine and the %~s1 magic string to get the 8.3 version of the file name:

echo on
set "WORKON_HOME=%TMP%\wo home %RANDOM%"
mkdir "%WORKON_HOME%"
cd /d "%WORKON_HOME%"
virtualenv "name with spaces"
cd "name with spaces"
call Scripts\activate.bat

call:shorten "%WORKON_HOME%\name with spaces",WO
call:shorten "%VIRTUAL_ENV%",VE

if "%WO%"=="%VE%" (
    echo workon home and virtualenv are equal
) else (
    echo. "%WORKON_HOME%\name with spaces" is not equal to "%VIRTUAL_ENV%"
)
goto:eof

:shorten
    for %%T in ("%~s1") do set "%~2=%%T"
    exit /b 0

Related