0

I want to dir a folder and get in a variable all the names of the *.csv files.

Does anyone know how can I do this?

1

2 Answers 2

3

Using Bash you can try:

dirlist=`ls -1 *.csv`
echo "$dirlist"

Under windows you can read the following Q and A:

Windows batch files: How to set a variable with the result of a command?

Something like:

for /f "delims=" %%a in ('dir') do @set foobar=%%a

Change 'dir' to what you want. I have no windows machine close by, so cannot test.

Sign up to request clarification or add additional context in comments.

2 Comments

Why answer a duplicate question?
And because it makes it easy for us Googlers to find the answer even when Google points us to the duplicate
0

I apologize for a duplicate response, but StackOverflow has reputation counters that impede me from certain actions.

When executing directly on the command-prompt, use the following form:

for /f "delims=" %a in ('whoami') do @set myaccount=%a

The form in previous answer is intended when used in a .bat or .cmd file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.