A
A
AlexandrMa2021-05-03 16:31:44
cmd/bat
AlexandrMa, 2021-05-03 16:31:44

How to create a variable with a file name?

How, using my code
1) create a result.txt variable in which the data will be saved
2) wrap to a new line (@echo: >> result.txt wraps with an extra space)

Source code

echo off
for %%f in ("C:\FOLDER\*.*") do (
@echo %%~nf >> result.txt
@echo %%~zf >> result.txt
@echo: >> result.txt
)


Did it, doesn't work
echo off
set filename = result.txt
for %%f in ("C:\FOLDER\*.*") do (
@echo %%~nf >> %filename%
@echo %%~zf >> %filename%
@echo: >> %filename%
)


The code itself runs through all the files in the C:\FOLDER folder and saves the data in this format
FILE NAME
SIZE
empty string

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AUser0, 2021-05-03
@AlexandrMa

@echo off
set filename=result.txt
for %%f in ("C:\FOLDER\*.*") do (
  echo %%~nf >>%filename%
  echo %%~zf >>%filename%
  echo. >>%filename%
)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question