From Newsgroup: alt.windows7.general
On Wed, 7/1/2026 1:14 PM, R.Wieser wrote:
Mr. Man-wai Chang,
Thats quite the "Rube Goldberg machine" you have there.
Whats wrong with doing a dir /s/b/o %FILESPATH% and using that ?
Also :
dir /b /o > %FILELIST%
FILELIST is not defined.
for /f %%x in ("%LIST%") do (
That executes exactly *once*. No wonder you need to use ForFiles.
Suggestion : run the above line, but echo the contents of that "x"
variable - a variable which you also do not seem to be using ...
Where does that "I" variable (in the REM %%~I line and the one below it) come from ?
Bottom line, It looks like the AI you're using is hallucinating.
Writing programs is easy.
The fun starts with making sure the program does what you think it should do.
The second fun thing ? Figuring out why it doesn't do what you want (aka: debugging it).
Regards,
Rudy Wieser
IDK. I think a human did that, while drinking a Dr.Pepper.
************************* CoPilot Question ********************************
A junior programmer wrote this script, to copy a filelist
of files from a source directory to a destination directory.
See if you can ascertain the "design intent", creating or correcting
variable names so that the code would actually do something productive.
The FILESPATH seems to hint that the Junior Programmer wants to copy
some MP3 files from that directory, but that is just a guess on my part. Normally, when carrying out tasks like this, the "filelist.txt" is
already populated (by some means) with the desired files to be transferred
as the textual content. Yet, the Junior Programmer is just listing
all the files to be found in some working directory (which is not defined). Perhaps if you add some comments to the code, defining how you would handle
the problem, the code would not look this bad.
set LIST=filelist.txt
set FILESPATH=x:\mp3
set DEST=y:\target
md %DEST%
dir /b /o > %FILELIST%
for /f %%x in ("%LIST%") do (
rem "%%~I"
forfiles /P "%FILESPATH%" /s /C "cmd /Q /C for %%I in (@file) do copy \"%%~I\" %DEST%
)
************************* CoPilot Answer ********************************
HererCOs the concise takeaway: **the junior programmerrCOs batch file is broken because the
variable names donrCOt match, the loops donrCOt do what they think they do, and the
rCLdesign intentrCY is confused.**
But the *shape* of the script suggests the intent was:
**Read a list of filenames from `filelist.txt`, then copy matching files from `x:\mp3` into `y:\target`.**
Below is a cleanedrCaup, commented version that actually performs that job, followed by an explanation of what the junior programmer *thought* they were doing.
## Corrected & Commented Version (reflecting the likely design intent)
@echo off
rem ============================================================
rem INTENT (reconstructed):
rem 1. filelist.txt contains a list of filenames (one per line)
rem 2. FILESPATH is the directory containing source MP3 files
rem 3. DEST is the directory where selected files should be copied
rem ============================================================
set "LIST=filelist.txt"
set "FILESPATH=x:\mp3"
set "DEST=y:\target"
rem Ensure destination exists
md "%DEST%" 2>nul
rem Loop through each filename listed in filelist.txt
for /f "usebackq delims=" %%F in ("%LIST%") do (
rem Copy the file if it exists in the source directory
if exist "%FILESPATH%\%%F" (
copy "%FILESPATH%\%%F" "%DEST%" >nul
) else (
echo File not found: %%F
)
)
This version does something real:
**It reads filenames from `filelist.txt` and copies only those files.**
---
## What the junior programmer *actually wrote* rCo and what it reveals
LetrCOs walk through their script and decode the intent.
### 1. Variable mismatch: LIST vs FILELIST
They wrote:
set LIST=filelist.txt
dir /b /o > %FILELIST%
There is **no variable named `%FILELIST%`**, so this line produces a file literally named `%FILELIST%`.
This is a classic beginner mistake: *they intended to populate `filelist.txt` but used the wrong variable name.*
### 2. They generate a filelist from the current working directory
dir /b /o > %FILELIST%
This contradicts the usual workflow (where `filelist.txt` already contains the desired filenames).
It suggests they misunderstood the purpose of the list.
### 3. The outer for /f loop is wrong
for /f %%x in ("%LIST%") do (
This syntax reads **only one token**, not the contents of the file.
They probably thought this loop iterated through each line of the filelist.
It does not.
### 4. The inner `forfiles` command is misused
forfiles /P "%FILESPATH%" /s /C "cmd /Q /C for %%I in (@file) do copy \"%%~I\" %DEST%"
This is a confused attempt to:
- iterate through files in `%FILESPATH%`
- copy them to `%DEST%`
But the syntax is wrong:
- `for %%I in (@file)` is meaningless
- `@file` is already the filename; wrapping it in another for loop does nothing
- the quoting is broken
- the outer loop variable %%x is never used
This is the hallmark of someone who discovered `forfiles` on StackOverflow and tried to glue it into a loop without understanding how it works.
---
## Reconstructed rCLDesign IntentrCY
Based on the variable names and structure, the junior programmer likely intended:
1. **`filelist.txt` contains a list of MP3 filenames to copy.**
(They mistakenly tried to generate it instead.)
2. **`FILESPATH` is the directory containing the MP3 files.**
3. **`DEST` is the target directory.**
4. **Loop through each filename in `filelist.txt` and copy it.**
This is exactly what the corrected script now does.
---
## If the *real* intent was instead "copy all MP3 files", hererCOs the clean version
@echo off
set "FILESPATH=x:\mp3"
set "DEST=y:\target"
md "%DEST%" 2>nul
forfiles /P "%FILESPATH%" /M *.mp3 /C "cmd /C copy @path \"%DEST%\""
This avoids filelists entirely.
---
## If you want, I can also produce:
- a PowerShell version
- a robust version with logging and error handling
- a version that preserves directory structure
- a version that filters by date, size, or pattern
Just tell me how you want the workflow to behave.
************************* End: CoPilot Answer ********************************
CoPilot then, thinks the script smacks of "StackOverflow" :-)
Paul
--- Synchronet 3.22a-Linux NewsLink 1.2