Obtaining one .dwg file from each directory in a list

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Craw
Posts: 3
Joined: 20 Dec 2021 08:16

Obtaining one .dwg file from each directory in a list

#1 Post by Craw » 20 Dec 2021 08:18

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

Compo
Posts: 599
Joined: 21 Mar 2014 08:50

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

#2 Post by Compo » 20 Dec 2021 12:57

"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!.

Craw
Posts: 3
Joined: 20 Dec 2021 08:16

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

#3 Post by Craw » 20 Dec 2021 13:16

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

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

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

#4 Post by Squashman » 20 Dec 2021 17:08

FOR /F is used to read a file.

Compo
Posts: 599
Joined: 21 Mar 2014 08:50

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

#5 Post by Compo » 20 Dec 2021 19:22

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 (

Craw
Posts: 3
Joined: 20 Dec 2021 08:16

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

#6 Post by Craw » 21 Dec 2021 07:31

Thank you @Squashman and @Compo.

Post Reply