Page 1 of 1

Obtaining one .dwg file from each directory in a list

Posted: 20 Dec 2021 08:18
by Craw
Hi, I have a list of directories that each contain several .dwg files. I would like to get the file path of one .dwg from each folder in the list and make a new list of these files for later processing.

Both lists are stored in text files. DirList.txt contains the input directories and 250List.txt contains the output dwg files.

Unfortunately, my script gives an error: "File Not Found" and appends "ECHO is off." to 250List.txt

Could someone lend me a hand in determining what is wrong with my code? Thanks.

Code: Select all

@echo off
cls
setlocal enabledelayedexpansion
FOR %%G IN (DirList.txt) DO (
for /f "delims=" %%F in ('dir %%G\*.dwg /b /o-n') do set file=%%F
echo %file%>>C:\Users\Craw\250\Last250List.txt
)
endlocal
pause

Re: Obtaining one .dwg file from each directory in a list

Posted: 20 Dec 2021 12:57
by Compo
"delims=" should be "eol=? delims=", %%G\*.dwg should be "%%G\*.dwg", file=%%F should be "File=%%F", and the most important one, %file% should be !File!.

Re: Obtaining one .dwg file from each directory in a list

Posted: 20 Dec 2021 13:16
by Craw
Thank you for your reply @Compo, unfortunately after making those changes, I still receive the same errors.

Code: Select all

@echo off
cls
setlocal enabledelayedexpansion
FOR %%G IN (DirList.txt) DO (
for /f "eol=? delims=" %%F in ('dir "%%G\*.dwg" /b /o-n') do set "File=%%F"
echo !File!>>"C:\Users\Craw\250\Last250List.txt"
)
endlocal
pause

Re: Obtaining one .dwg file from each directory in a list

Posted: 20 Dec 2021 17:08
by Squashman
FOR /F is used to read a file.

Re: Obtaining one .dwg file from each directory in a list

Posted: 20 Dec 2021 19:22
by Compo
Okay now, based on the adivce of Squashman, change:
Craw wrote:
20 Dec 2021 13:16

Code: Select all

FOR %%G IN (DirList.txt) DO (
To:

Code: Select all

For /F "UseBackQ EOL=? Delims=" %%G In ("DirList.txt") Do (

Re: Obtaining one .dwg file from each directory in a list

Posted: 21 Dec 2021 07:31
by Craw
Thank you @Squashman and @Compo.