I want to drag and drop folders/files print out all dirs/files and files of its subfolder recursively into a file.
@echo off
REM chcp 1250
REM chcp 65001
if [%1]==[] goto :eof
:loop
echo %1 >> aText.txt
for /f "tokens=* delims=" %%a in ('dir %1 /s /b') do (
echo %%a >> aText.txt
)
shift
if not [%1]==[] goto loop
aText.txt
@pause
And that works fine, but it doesn't support Unicode filenames. It also doesn't work, if I save the bat file itself under UTF-8 or Unicode. I have looked at this: Unicode characters in Windows command line - how?
But this doesn't make it work. My guess is, the chcp makes it possible to write unicode in the batch file, and not unicode in the file it creates. How do I get the unicode filenames written into the file it creates?
EDIT:
To re-phrase my question more precisely. I want to write this unicode to be readable by the browser (e.g. Chrome mostly) What I have now is this:
@echo off
chcp 65001
if [%1]==[] goto :eof
:loop
echo %1 > aText.txt
for /f "tokens=* delims=" %%a in ('dir %1 /s /b') do (
echo ^<br^>^<img src='%%a'^> >> aText.txt
REM echo %%a >> aText.txt
)
shift
if not [%1]==[] goto loop
aText.txt
@pause
So I open this in notepad, it shows the unicode, all fine. (Just as MC ND describes in the answer) This gives me:
D:\Downloads\unicodes
<br><img src='D:\Downloads\unicodes\sdsdsd.html'>
<br><img src='D:\Downloads\unicodes\ŽŽŽŽŽ.png'>
<br><img src='D:\Downloads\unicodes\中文.png'>
<br><img src='D:\Downloads\unicodes\文言.png'>
<br><img src='D:\Downloads\unicodes\日本語.png'>
<br><img src='D:\Downloads\unicodes\日本語.txt'>
<br><img src='D:\Downloads\unicodes\粵語.png'>
<br><img src='D:\Downloads\unicodes\한국어.png'>
However, when I open this with Chrome it gets:
D:\Downloads\unicodes
<br><img src='D:\Downloads\unicodes\sdsdsd - Kopie.txt'>
<br><img src='D:\Downloads\unicodes\sdsdsd.html'>
<br><img src='D:\Downloads\unicodes\ŽŽŽŽŽ.png'>
<br><img src='D:\Downloads\unicodes\䏿–‡.png'>
<br><img src='D:\Downloads\unicodes\文言.png'>
<br><img src='D:\Downloads\unicodes\日本語.png'>
<br><img src='D:\Downloads\unicodes\日本語.txt'>
<br><img src='D:\Downloads\unicodes\粵語.png'>
<br><img src='D:\Downloads\unicodes\한êµì–´.png'>
obviously, when I rename the txt file to an html file, there is just a bunch of broken images even for the png files.
When I manually open the txt in notepad and re-save the txt file under a diffrent name, not even changing any of the set encodings (UTF-8), all works fine, as I want it, but I need to get rid of this manual saving.
With npocmaka's CM \u solution I was getting something with spaces inbetween each character, unfortunately I suddenly don't seem to be able to reproduce this after trying around uselessly, and instead with this now:
@echo off
chcp 65001
cmd /u /c for /f "tokens=* delims=" %%a in ('dir %1 /s /b') do ( echo %%a >> aText.txt )
aText.txt
I get
D:\Downloads>(echo D:\Downloads\unicodes\sdsdsd.html )
D:\Downloads\unicodes\sdsdsd.html
D:\Downloads>(echo D:\Downloads\unicodes\ŽŽŽŽŽ.png )
D:\Downloads\unicodes\ŽŽŽŽŽ.png
D:\Downloads>(echo D:\Downloads\unicodes\中文.png )
D:\Downloads\unicodes\中文.png
D:\Downloads>(echo D:\Downloads\unicodes\文言.png )
D:\Downloads\unicodes\文言.png
D:\Downloads>(echo D:\Downloads\unicodes\日本語.png )
D:\Downloads\unicodes\日本語.png
D:\Downloads>(echo D:\Downloads\unicodes\日本語.txt )
D:\Downloads\unicodes\日本語.txt
D:\Downloads>(echo D:\Downloads\unicodes\粵語.png )
D:\Downloads\unicodes\粵語.png
D:\Downloads>(echo D:\Downloads\unicodes\한국어.png )
D:\Downloads\unicodes\한국어.png
whose double line output despite the echo off in itself is weird for me, but at any rate, in notepad the unicode filesnames are shown, but chrome would not want even want to open the txt, and upon renaming the extention to html, it shows "garbage" as follows:
D:\Downloads>(echo D:\Downloads\unicodes\sdsdsd.html ) D:\Downloads\unicodes\sdsdsd.html D:\Downloads>(echo D:\Downloads\unicodes\}}}}}.png ) D:\Downloads\unicodes\}}}}}.png D:\Downloads>(echo D:\Downloads\unicodes\-N‡e.png ) D:\Downloads\unicodes\-N‡e.png D:\Downloads>(echo D:\Downloads\unicodes\‡eŠ.png ) D:\Downloads\unicodes\‡eŠ.png D:\Downloads>(echo D:\Downloads\unicodes\åe,gžŠ.png ) D:\Downloads\unicodes\åe,gžŠ.png D:\Downloads>(echo D:\Downloads\unicodes\åe,gžŠ.txt ) D:\Downloads\unicodes\åe,gžŠ.txt D:\Downloads>(echo D:\Downloads\unicodes\µ|žŠ.png ) D:\Downloads\unicodes\µ|žŠ.png D:\Downloads>(echo D:\Downloads\unicodes\\Õm´Å.png ) D:\Downloads\unicodes\\Õm´Å.png
which is not what I need...