I tried to list all files and directories on a directory by using this format
dir1:::dir2:::file1:::file2:::
To achieve this, I wrote a batch script. Take a look at it :
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
SET M=
FOR %%d IN ('dir /B') DO SET M=!M!%%d:::
ECHO %M%
Well, it works for directories/files that doesn’t contain spaces, but for those that contained it, it will show just the first word.
For example, suppose the files are “Blue hills.jpg” and “Sunset.jpg”.
The expected result is of course
Blue hills.jpg:::Sunset.jpg:::
But what appears instead is
Blue:::Sunset.jpg
FYI, I use WinXP. *Is that matter? I’ve tried to put quotes in “%%d” but it doesn’t work. How can I fix this?
Thanks for the help! And sorry for my bad english, I really have to improve it..
You need to run your
forloop for file names containing any text (spaces included)"tokens=*". The/fswitch is to search for text (filename text).Works for files and directories with spaces.
If you use
tokens=1then you get the first word of each file name (using a space as separator). So you would seeIf you use
tokens=2then you get the second word: