2016-09-06 9 views
1

私は、次のバッチファイルがあります。これは、テキストファイルに現在のディレクトリ内のすべてのjpgファイルのパスを出力しバッチファイル出力ユニコード

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

を、問題は、ディレクトリは私ではないということですが、共有パスにはスペイン語の特殊文字が含まれています。代わりに出力するのでそう:

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

をそれはあなたがこのコードは出力にUnicodeをトリックをやったことができ、このオプション/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. 

CMD.exeを使用する必要があります

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

私は次のことをチェックアウトするだろうhttp://stackoverflow.com/a/ 388500/2524589。これらをまとめてみると、 "chcp"を実行してアクティブコードページを手に入れ、 "chcp 65001"を実行し、dirコマンドを実行して元のコードページで "chcp"を実行するようにします。私はこれをテストすることはできませんので、私はここにコメントの中に残しました。 – KSib

答えて

2

を出力します文字:

のより多くのオプションについて

@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%" 

私はこの1つのような、より複雑なコードでこのトリックを使用:

@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

それは、おかげで、ありがとう。ところで、どの言語がバッチファイルですか?私はそれがワークフローを最適化するのに非常に役立つかもしれないので、それを学びたいと思います。 –

関連する問題