I have a folder folder1
contain 3 files file1
, file2
and file3
, etc.
I need command line to do the following task.
Store the name of the files in a variable because I want to write a dynamic batch.
I have a folder folder1
contain 3 files file1
, file2
and file3
, etc.
I need command line to do the following task.
Store the name of the files in a variable because I want to write a dynamic batch.
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.If you quote the
%%f
, theecho
will output the quotes around the filename, but if you want to pass the filename to other commands the quotes may be necessary if there are special characters, such as spaces, in the filenames. For example, to output the contents of all the files:Without the quotes, if there was a file named "Has Space",
type
would try to output the contents of two files, "Has" and "Space". With the quotes, it will work as intended.If you want to upgrade from batch to powershell:
Assuming this is in a batch file, you could do it in a for loop like this: