2016-09-06 81 views
1

我有以下批处理文件:批处理文件输出的Unicode

dir *.jpg /b /s >> out.txt 

它输出在当前目录到一个文本文件中的所有JPG文件的路径,问题是该目录是不是我的,但共享通过网络,路径包含西班牙特殊字符。因此,而不是输出:

---------------v--------- 
...\Participación ciud... 

它输出

---------------v--------- 
...\Participaci¢n ciud... 
+1

我想看看下面的http://stackoverflow.com/a/ 2524589分之388500。将这些拼接在一起听起来像是你运行“chcp”来获得你的活动代码页,以防你想修改它,运行“chcp 65001”,运行你的dir命令,然后用你原来的代码页运行“chcp”。我无法测试这个,所以我把它留在评论中。 – KSib

回答

2

你应该使用CMD.exe使用此选项/U

/U  Output UNICODE characters (UCS-2 le) 
      These options will affect piping or redirecting to a file. 
      Most common text files are ANSI, use these switches 
      when you need to convert the character set. 

这个代码可以做的伎俩输出的Unicode字符:

@echo off 
Set "TmpLogFile=%Tmp%\%~n0.txt" 
Set "LogFile=%~dp0%~n0.txt" 
If Exist "%TmpLogFile%" Del "%TmpLogFile%" 
dir *.jpg /b /s >> %TmpLogFile% 
REM Formatting the output to unicode 
CMD /U /C Type "%TmpLogFile%" > "%LogFile%" 
Start "" "%LogFile%" 

对于CMD.exe /?

更多的选择我用这一招在一个更复杂的代码,像这样的:

@ECHO OFF 
Title Scan a folder and store all files names in an array variables 
SET "ROOT=%userprofile%\Desktop\" 
SET "EXT=jpg" 
SET "Count=0" 
Set "TmpLogFile=%Tmp%\%~n0.txt" 
Set "LogFile=%~dp0%~n0.txt" 
SETLOCAL enabledelayedexpansion 
REM Iterates throw the files on this current folder and its subfolders. 
REM And Populate the array with existent files in this folder and its subfolders 
For %%a in (%EXT%) Do ( 
    Call :Scanning "*.%%a" & timeout /T 2 /Nobreak>nul 
    FOR /f "delims=" %%f IN ('dir /b /s "%ROOT%\*.%%a"') DO (
     Call :Scanning "%%f" 
     SET /a "Count+=1" 
     set "list[!Count!]=%%~nxf" 
     set "listpath[!Count!]=%%~dpFf" 
    ) 
) 
::*************************************************************** 
:Display_Results 
cls & color 0B 
echo wscript.echo Len("%ROOT%"^) + 20 >"%tmp%\length.vbs" 
for /f %%a in ('Cscript /nologo "%tmp%\length.vbs"') do (set "cols=%%a") 
If %cols% LSS 50 set /a cols=%cols% + 15 
set /a lines=%Count% + 10 
Mode con cols=%cols% lines=%lines% 
ECHO ******************************************************** 
ECHO Folder:"%ROOT%" 
ECHO ******************************************************** 
If Exist "%TmpLogFile%" Del "%TmpLogFile%" 
rem Display array elements and save results into the TmpLogFile 
for /L %%i in (1,1,%Count%) do (
    echo [%%i] : !list[%%i]! 
    echo [%%i] : !list[%%i]! -- "!listpath[%%i]!" >> "%TmpLogFile%"  
) 

(ECHO. & ECHO Total of [%EXT%] files(s^) : %Count% file(s^))>> "%TmpLogFile%" 
REM Formatting the TmpLogFile to the unicode LogFile : 
CMD /U /C Type "%TmpLogFile%" > "%LogFile%" 
ECHO(
ECHO Total of [%EXT%] files(s) : %Count% file(s) 
echo(
echo Type the number of file did you want to explore ? 
set /p "Input=" 
For /L %%i in (1,1,%Count%) Do (
    If "%INPUT%" EQU "%%i" (
     Call :Explorer "!listpath[%%i]!" 
    ) 
) 
Goto:Display_Results 
::************************************************************** 
:Scanning <file> 
mode con cols=75 lines=3 
Cls & Color 0E 
echo(
echo Scanning for "%~1" ... 
goto :eof 
::************************************************************* 
:Explorer <file> 
explorer.exe /e,/select,"%~1" 
Goto :EOF 
::************************************************************* 
+0

这样做,谢谢。顺便说一句,批处理文件是什么语言?我想了解它,因为它对优化工作流程非常有用。 –

相关问题