   @echo off
   setlocal
   set cpActive=0
   set cpOEM=0

      : rem check for existence of CHCP.COM, REG.EXE
   copy ::: nul 2>nul
   chcp.com /? >nul
   if not errorlevel 1 (
      copy ::: nul 2>nul
      reg.exe /? >nul
   )
   if errorlevel 1 (
      echo.
      echo *** Warning^: REG.EXE and/or CHCP.COM not found ^(see error message above^), 
      goto NoCpSwitch
   )
   copy nul nul >nul

      : rem get local codepage numbers; thanks 2 Dalai for this
   for /f "skip=4 tokens=3" %%i in ('reg.exe query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage" /v "ACP"') do (
     set cpActive=%%i
   )
   for /f "skip=4 tokens=3" %%i in ('reg.exe query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage" /v "OEMCP"') do (
     set cpOEM=%%i
   )
   for %%e in ("%cpActive%") do for %%f in ("%cpOEM%") do goto Start
   echo *** Warning^: Could not retrieve codepage information with REG.EXE,
   goto NoCpSwitch   

:Start   
      : rem load ANSI codepage
   chcp.com %cpActive% > NUL

:NoCpSwitch
   if     "%~1"=="" echo Syntax:&echo    %~nx0 "d:\path\filelist.txt"    &goto ce
   
   for /F "usebackq tokens=* delims= " %%e in ("%~1") do @for /F "usebackq tokens=1 delims= " %%f in ('%%~te') do (
      md %%f 2>nul
      move "%%~dpnxe" "%%~dpe\%%~f\%%~nxe"
   )
   
   goto ce

:ce
      : rem load ASCII/OEM codepage again
   if not "%cpOEM%"=="0" chcp.com %cpOEM% >nul

:ex

   : rem Syntax:   %~nx0 "d:\path\filelist.txt"
