• Batch file to copy files based on a list

    From Mr. Man-wai Chang@toylet.toylet@gmail.com to alt.msdos.batch,alt.windows7.general,alt.msdos.batch.nt,alt.comp.os.windows-10 on Wed Jul 1 23:46:07 2026
    From Newsgroup: alt.windows7.general



    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%
    )
    --

    @~@ Simplicity is Beauty! Remain silent! Drink, Blink, Stretch!
    / v \ May the Force and farces be with you! Live long and prosper!!
    /( _ )\ https://sites.google.com/site/changmw/
    ^ ^ https://github.com/changmw/changmw
    The game is afoot... Meow...

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From R.Wieser@address@is.invalid to alt.msdos.batch,alt.windows7.general,alt.msdos.batch.nt,alt.comp.os.windows-10 on Wed Jul 1 19:14:12 2026
    From Newsgroup: alt.windows7.general

    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


    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Paul@nospam@needed.invalid to alt.msdos.batch,alt.windows7.general,alt.msdos.batch.nt,alt.comp.os.windows-10 on Wed Jul 1 14:11:30 2026
    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
  • From R.Wieser@address@is.invalid to alt.msdos.batch,alt.windows7.general,alt.msdos.batch.nt,alt.comp.os.windows-10 on Wed Jul 1 21:06:17 2026
    From Newsgroup: alt.windows7.general

    Paul,

    Bottom line, It looks like the AI you're using is hallucinating.
    ...
    IDK. I think a human did that, while drinking a Dr.Pepper.

    What makes you think I thought anything else ? :-) I didn't want to /say/
    it though.

    Although I didn't mind that you let CoPilot infer the OP's intention, I'd rather seen you trying to /help/ the OP, instead of posting a/the solution. How will he ever learn what those batch commands in his script do and how to use them, when he can just copy-paste someone elses work ?

    And by the way : the "/s" switch to "forfiles" indicates subdirectories too. It looks like Copilot missed it.

    Regards,
    Rudy Wieser


    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Alan K.@alan@invalid.com to alt.msdos.batch,alt.windows7.general,alt.msdos.batch.nt,alt.comp.os.windows-10 on Wed Jul 1 16:38:41 2026
    From Newsgroup: alt.windows7.general

    On 7/1/26 3:06 PM, R.Wieser wrote:
    Paul,

    Bottom line, It looks like the AI you're using is hallucinating.
    ...
    IDK. I think a human did that, while drinking a Dr.Pepper.

    What makes you think I thought anything else ? :-) I didn't want to /say/ it though.

    Although I didn't mind that you let CoPilot infer the OP's intention, I'd rather seen you trying to /help/ the OP, instead of posting a/the solution. How will he ever learn what those batch commands in his script do and how to use them, when he can just copy-paste someone elses work ?

    And by the way : the "/s" switch to "forfiles" indicates subdirectories too. It looks like Copilot missed it.

    Regards,
    Rudy Wieser


    I let copilot do a lot of my small scripts in Linux and find that I usually have to tweak
    it somehow, either telling copilot to do it, or doing it myself.
    --
    Mint 22.3, Thunderbird 140.12.0esr, Firefox 152.0.3
    Alan K.
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Paul@nospam@needed.invalid to alt.msdos.batch,alt.windows7.general,alt.msdos.batch.nt,alt.comp.os.windows-10 on Wed Jul 1 21:17:34 2026
    From Newsgroup: alt.windows7.general

    On Wed, 7/1/2026 4:38 PM, Alan K. wrote:
    On 7/1/26 3:06 PM, R.Wieser wrote:
    Paul,

    Bottom line, It looks like the AI you're using is hallucinating.
    ...
    IDK. I think a human did that, while drinking a Dr.Pepper.

    What makes you think I thought anything else ? :-)-a-a I didn't want to /say/
    it though.

    Although I didn't mind that you let CoPilot infer the OP's intention, I'd
    rather seen you trying to /help/ the OP, instead of posting a/the solution. >> How will he ever learn what those batch commands in his script do and how to >> use them, when he can just copy-paste someone elses work ?

    And by the way : the "/s" switch to "forfiles" indicates subdirectories too. >> It looks like Copilot missed it.

    Regards,
    Rudy Wieser


    I let copilot do a lot of my small scripts in Linux and find that I usually have to tweak it somehow, either telling copilot to do it, or doing it myself.


    One thing I try to do, when I write a script by hand,
    is I try to capture "prototypes" or a sampling of
    my intentions, at the top of the script. This allows
    me to refer back to actual (good or bad) examples of what
    the script is trying to do. Someone can look at my script
    then and say "hmmm, design intent does not match implementation".
    But at least they can see via my straw man examples at
    the top of the page, what my plan was.

    This is why, we couldn't really write a script, without
    a better specification of what the individual is after.
    If you "considered every possibility", it could be a
    hundred thousand lines of code.

    For example, if I tar up a tree, it's got everything in it,
    I have no fear of losing anything. If I don't have a
    specification, such an implementation hasn't lost anything.

    *******

    Writing scripts should not be necessary. The audience
    was probably willing to point this out, but this topic
    has come up before so why bother. Here is why.

    1) Open File Explorer.
    2) Highlight top of source tree x:\mp3
    3) Go to search box, upper right. Enter "ext:mp3" without the double quotes.
    This selects every file with that extension (does not require Search Indexer
    to be programmed or up-to-date).
    4) Now, the search results have a subset of the tree. Control-A to select all.
    Select Copy.
    5) Navigate to destination directory. Select Paste.

    With the right hot-key-combo, you can also knock
    out single entries from the selection or add single
    entries to the selection. If you didn't like my search
    specification, you could select files one by one with
    the right hot-key-combo.

    Maybe a tool like XYExplorer could do this too.

    There's nothing wrong with scripting, as long as
    you select a subset of the entire application
    space for your effort. If you really really want
    an anything goes tool, a commercial tool that
    costs money may be the right answer. Rewriting this
    same code, over and over again... I guess that
    builds character.

    Paul
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Paul@nospam@needed.invalid to alt.msdos.batch,alt.windows7.general,alt.msdos.batch.nt,alt.comp.os.windows-10 on Wed Jul 1 23:29:32 2026
    From Newsgroup: alt.windows7.general

    On Wed, 7/1/2026 4:38 PM, Alan K. wrote:
    On 7/1/26 3:06 PM, R.Wieser wrote:
    Paul,

    Bottom line, It looks like the AI you're using is hallucinating.
    ...
    IDK. I think a human did that, while drinking a Dr.Pepper.

    What makes you think I thought anything else ? :-)-a-a I didn't want to /say/
    it though.

    Although I didn't mind that you let CoPilot infer the OP's intention, I'd
    rather seen you trying to /help/ the OP, instead of posting a/the solution. >> How will he ever learn what those batch commands in his script do and how to >> use them, when he can just copy-paste someone elses work ?

    And by the way : the "/s" switch to "forfiles" indicates subdirectories too. >> It looks like Copilot missed it.

    Regards,
    Rudy Wieser


    I let copilot do a lot of my small scripts in Linux and find
    that I usually have to tweak it somehow, either telling copilot
    to do it, or doing it myself.

    The design is intended to burn up tokens.

    At one time, it would do something kinda human. It would
    find a sample code, then add to it. But there have also been
    instances where it got "lazy", with some funny results.

    I don't think I would be particularly happy, if I was paying
    for the tokens.

    I have an LLM-AI file loaded on the other machine,
    but haven't given it programming tasks. So far the evidence
    suggests it is quite limited on context somehow.

    Paul



    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Mr. Man-wai Chang@toylet.toylet@gmail.com to alt.msdos.batch,alt.windows7.general,alt.msdos.batch.nt,alt.comp.os.windows-10 on Thu Jul 2 12:27:00 2026
    From Newsgroup: alt.windows7.general

    On 7/2/2026 1:14 AM, R.Wieser wrote:


    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).

    Master, it's a work-in-progress.
    I am using this newsgroup as a
    notebook.
    --

    @~@ Simplicity is Beauty! Remain silent! Drink, Blink, Stretch!
    / v \ May the Force and farces be with you! Live long and prosper!!
    /( _ )\ https://sites.google.com/site/changmw/
    ^ ^ https://github.com/changmw/changmw
    The game is afoot... Meow...
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From R.Wieser@address@is.invalid to alt.msdos.batch,alt.windows7.general,alt.msdos.batch.nt,alt.comp.os.windows-10 on Thu Jul 2 09:02:24 2026
    From Newsgroup: alt.windows7.general

    Mr. Man-wai Chang,

    I am using this newsgroup as a
    notebook.

    Well, there is your problem.

    ... besides that you are dumping your "notes" into four newsgroups.

    Regards,
    Rudy Wieser


    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Mr. Man-wai Chang@toylet.toylet@gmail.com to alt.msdos.batch,alt.windows7.general,alt.msdos.batch.nt,alt.comp.os.windows-10 on Thu Jul 2 19:06:57 2026
    From Newsgroup: alt.windows7.general

    On 7/2/2026 3:02 PM, R.Wieser wrote:
    Mr. Man-wai Chang,

    I am using this newsgroup as a
    notebook.

    Well, there is your problem.
    ... besides that you are dumping your "notes" into four newsgroups.

    The script is un-finished...
    --

    @~@ Simplicity is Beauty! Remain silent! Drink, Blink, Stretch!
    / v \ May the Force and farces be with you! Live long and prosper!!
    /( _ )\ https://sites.google.com/site/changmw/
    ^ ^ https://github.com/changmw/changmw
    The game is afoot... Meow...
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Paul@nospam@needed.invalid to alt.msdos.batch,alt.windows7.general,alt.comp.os.windows-10 on Thu Jul 2 08:55:02 2026
    From Newsgroup: alt.windows7.general

    On Thu, 7/2/2026 7:06 AM, Mr. Man-wai Chang wrote:
    On 7/2/2026 3:02 PM, R.Wieser wrote:
    Mr. Man-wai Chang,

    I am using this newsgroup as a
    notebook.

    Well, there is your problem.
    ... besides that you are dumping your "notes" into four newsgroups.

    The script is un-finished...


    To copy files, you don't even need a script.

    To copy files, you can use Robocopy.
    Robocopy is a "directory copy program". Basically, it can
    copy the contents of one directory to another. Using its mirror
    option, is an advanced topic. First, we practice basic copying.

    *******

    You have not given a textual description of the

    intended usage

    of the script. Do you intend to use the script ?

    You could show us the dir listing of the source
    directory, whether it has mixed file extensions or
    uniform files sorted into directories.

    *******

    When you write a script that copies files or deletes files,
    you replace the "copy" or "del" with "echo" so that you
    can see what the command would have done, if you had allowed
    it. This is called "dry run" in some programs. In this example,
    that is /L .

    robocopy x:\mp3 y:\target *.mp3 /S /L /tee /v /log:C:\temp\my-mp3-backup.log

    /S = recursive but not empty folders (/E for recursive plus empty folders)
    /L = dry run
    (The stuff on the end is "plenty verbose" options)

    X:.
    rooroCroCroCmp3
    roLroCroCroCbelow
    roe roe 01.mp3
    roe roe 02.txt
    roe roe 03.txt
    roe roe 04.txt
    roe roe
    roe rooroCroCroCdownbelow
    roe 01.mp3
    roe 02.txt
    roe 03.txt
    roe 04.txt
    roe
    roLroCroCroCno
    roe 01.txt
    roe 02.txt
    roe 03.txt
    roe 04.txt
    roe
    roLroCroCroCsome
    roe 01.mp3
    roe 02.txt
    roe 03.txt
    roe 04.txt
    roe
    rooroCroCroCyes
    01.mp3
    02.mp3
    03.mp3
    04.mp3

    *******

    robocopy x:\mp3 y:\target *.mp3 /S /L

    Log File : C:\temp\my-mp3-backup.log

    New Dir 0 x:\mp3\
    New Dir 1 x:\mp3\below\
    New File 0 01.mp3
    New Dir 1 x:\mp3\below\downbelow\
    New File 0 01.mp3
    New Dir 0 x:\mp3\no\
    New Dir 1 x:\mp3\some\
    New File 0 01.mp3
    New Dir 4 x:\mp3\yes\
    New File 0 01.mp3
    New File 0 02.mp3
    New File 0 03.mp3
    New File 0 04.mp3

    Now, do the command for real, and list the results with "tree /F".
    It does not make the "no" directory, even though the log
    mentions a New Dir. Using /E would create an empty "no" directory.

    robocopy x:\mp3 y:\target *.mp3 /S /tee /v /log:C:\temp\my-mp3-backup.log

    Y:\target>tree /F
    Folder PATH listing for volume DEST
    Volume serial number is 0000005E 1C52:F907
    Y:.
    roLroCroCroCbelow
    roe roe 01.mp3
    roe roe
    roe rooroCroCroCdownbelow
    roe 01.mp3
    roe
    roLroCroCroCsome
    roe 01.mp3
    roe
    rooroCroCroCyes
    01.mp3
    02.mp3
    03.mp3
    04.mp3

    That's plenty of power for a neophyte. If I wanted the artwork
    copied in each folder as well, then just remove the file selector *.mp3 .

    Paul


    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Mr. Man-wai Chang@toylet.toylet@gmail.com to alt.msdos.batch,alt.windows7.general,alt.comp.os.windows-10 on Thu Jul 2 22:17:37 2026
    From Newsgroup: alt.windows7.general

    On 7/2/2026 8:55 PM, Paul wrote:

    To copy files, you don't even need a script.

    To copy files, you can use Robocopy.
    Robocopy is a "directory copy program"....


    I wanna shuffle the lines in the file list
    and then copy them. That's why I said the
    script is not yet finished.

    I am now looking for DOS / Windows batch
    script to shuffle lines in a plain-text
    file.
    --

    @~@ Simplicity is Beauty! Remain silent! Drink, Blink, Stretch!
    / v \ May the Force and farces be with you! Live long and prosper!!
    /( _ )\ https://sites.google.com/site/changmw/
    ^ ^ https://github.com/changmw/changmw
    The game is afoot... Meow...
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From R.Wieser@address@is.invalid to alt.msdos.batch,alt.windows7.general,alt.msdos.batch.nt,alt.comp.os.windows-10 on Thu Jul 2 22:05:04 2026
    From Newsgroup: alt.windows7.general

    Mr. Man-wai Chang,

    I am using this newsgroup as a
    notebook.

    Well, there is your problem.
    ... besides that you are dumping your "notes" into four newsgroups.

    The script is un-finished...

    And that makes a difference... how ? Dump (save) your (un)finished scripts in a folder on your own 'puter. That is why you have one and what all that disk-space is for.

    Also, that script isn't unfinished, its a joke.

    I gave you a few pointers, but I've not seen you respond to it. Thats alright, you just do not want to learn. Which means that I do not need to spend time trying to help you.

    Regards,
    Rudy Wieser


    --- Synchronet 3.22a-Linux NewsLink 1.2