Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

i have a folder folder1 contain 3 files file1 , file2 and file3 ... i need command line to do the following task ... store the name of file in variable ... because i want to write dynamic batch

share|improve this question

3 Answers 3

up vote 2 down vote accepted
FOR %%f in (folder1\*) DO @echo %%f

in a batch file will echo the filename of each file in the folder. To do the same thing at the command line, use only one percent sign for the variable. You can replace echo with some other command.

share|improve this answer

If you want to upgrade from batch to powershell:

Foreach ($file in Get-Childitem "<PATH>") {
    $file.name
}
share|improve this answer
    
Or simply gci <path> | select Name. –  Joey Dec 23 '10 at 22:10

Assuming this is in a batch file, you could do it in a for loop like this:

setlocal EnableDelayedExpansion 

for %%a in (folder1\*) do (
set fileVariable=%%a
echo !fileVariable!
)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.