DOS equivalent of linux command pass
Moderator: DosItHelp
-
- Posts: 2
- Joined: 22 Jan 2015 10:11
DOS equivalent of linux command pass
Hello,
I'm totally new to DOS, but am pretty comfortable with bash shell scripting. One of my functions requires (in bash) as a parameter "$(ls *.txt)" (i.e. I need the function to read in a space-delimited list of all the text files in the current folder). Does anyone know a DOS equivalent to this command?
Cheers!
I'm totally new to DOS, but am pretty comfortable with bash shell scripting. One of my functions requires (in bash) as a parameter "$(ls *.txt)" (i.e. I need the function to read in a space-delimited list of all the text files in the current folder). Does anyone know a DOS equivalent to this command?
Cheers!
Re: DOS equivalent of linux command pass
The equivalent command of BASH LS is DIR in the NT CMD shell. But I am confused by the rest of your comments.
Please provide a more detailed explanation of what you are trying to do.
Please provide a more detailed explanation of what you are trying to do.
-
- Expert
- Posts: 1167
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: DOS equivalent of linux command pass
Isn't $(ls *.txt) a value containing the output of the command ls *.txt?
You could say something like
You could say something like
Code: Select all
for /F %%A in (dir /b *.txt) do (
call yourFunction %%A
)
Re: DOS equivalent of linux command pass
ShadowThief wrote:Isn't $(ls *.txt) a value containing the output of the command ls *.txt?
You could say something like
This is a little more robust (based on your suggestion)

Code: Select all
for /F "delims=" %%A in ('dir /b /a-d *.txt') do (
call :yourFunction "%%A"
)
-
- Expert
- Posts: 1167
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: DOS equivalent of linux command pass
I left out the "delims=" because they wanted a space-delimited string, but yeah, good call on the /a:-d
Re: DOS equivalent of linux command pass
The space delimited kind of confused me. I am not sure if they meant each file name is separated by a space in a file all on one line or that the files themselves have space delimited data.
Re: DOS equivalent of linux command pass
ShadowThief wrote:I left out the "delims=" because they wanted a space-delimited string
Squashman wrote:The space delimited kind of confused me.
I sorta glossed over that myself. Maybe the OP can be more descriptive.
-
- Posts: 2
- Joined: 22 Jan 2015 10:11
Re: DOS equivalent of linux command pass
Sorry for being a bit cryptic in my question! I probably should have mentioned my function is written in python.
Using $(ls *.txt) as an argument to the function passes a list of all text files in the current directory, whereas using "$(ls *.txt)" with inverted commas passes a single value that is all the text files in the directory separated by spaces. Hope that's clearer...
Using $(ls *.txt) as an argument to the function passes a list of all text files in the current directory, whereas using "$(ls *.txt)" with inverted commas passes a single value that is all the text files in the directory separated by spaces. Hope that's clearer...
Re: DOS equivalent of linux command pass
First time I have heard someone call quotes inverted commas.
So none of the actual file names have spaces. If they do, that would be a problem if the file names with spaces are not surrounded by "inverted commas".
So none of the actual file names have spaces. If they do, that would be a problem if the file names with spaces are not surrounded by "inverted commas".

Re: DOS equivalent of linux command pass
dosconfusesme wrote:Sorry for being a bit cryptic in my question! I probably should have mentioned my function is written in python.
...Hope that's clearer...
What would be clearer is to describe what you need to do with the filenames, if the filenames have spaces or unicode or non-latin characters,
and if you need to process a single folder or folder tree.