DOS equivalent of linux command pass

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
dosconfusesme
Posts: 2
Joined: 22 Jan 2015 10:11

DOS equivalent of linux command pass

#1 Post by dosconfusesme » 22 Jan 2015 10:15

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!

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: DOS equivalent of linux command pass

#2 Post by Squashman » 22 Jan 2015 12:34

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.

ShadowThief
Expert
Posts: 1167
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: DOS equivalent of linux command pass

#3 Post by ShadowThief » 22 Jan 2015 17:39

Isn't $(ls *.txt) a value containing the output of the command ls *.txt?

You could say something like

Code: Select all

for /F %%A in (dir /b *.txt) do (
    call yourFunction %%A
)

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: DOS equivalent of linux command pass

#4 Post by foxidrive » 22 Jan 2015 19:19

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"
)

ShadowThief
Expert
Posts: 1167
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: DOS equivalent of linux command pass

#5 Post by ShadowThief » 22 Jan 2015 19:51

I left out the "delims=" because they wanted a space-delimited string, but yeah, good call on the /a:-d

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: DOS equivalent of linux command pass

#6 Post by Squashman » 22 Jan 2015 21:02

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.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: DOS equivalent of linux command pass

#7 Post by foxidrive » 23 Jan 2015 02:59

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.

dosconfusesme
Posts: 2
Joined: 22 Jan 2015 10:11

Re: DOS equivalent of linux command pass

#8 Post by dosconfusesme » 23 Jan 2015 03:37

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...

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: DOS equivalent of linux command pass

#9 Post by Squashman » 23 Jan 2015 07:13

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". ;)

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: DOS equivalent of linux command pass

#10 Post by foxidrive » 23 Jan 2015 19:14

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.

Post Reply