Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7431527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:18:34+00:00 2026-05-29T09:18:34+00:00

I have a windows boot pen that runs a batch file when it starts

  • 0

I have a windows boot pen that runs a batch file when it starts up, all it needs to do is copy a large list of files specified in a text file from the machine to the boot pen.

I made a test run on my PC before making the boot pen and thought this should work

@echo off
set DRIVE=c

for /F "tokens=*" %%a in (e:\test\files.txt) do call :amendDirectoryAndCopy %%a

pause

:amendDirectoryAndCopy
set DEST=%~1
set DEST=%DEST:~1%
echo set DEST=%DRIVE%%DEST%
echo xcopy %~1 %DEST%

all it should do is for each file, remove the first character of the string, add “c” to the beginning which gives the destination directory, then perform an xcopy. I find the output confusing as “@echo set “DEST=%DRIVE%%DEST%” outputs what I would expect, the correct directory on C: such as

c:\test\folder\file.txt

but the xcopy outputs

xcopy e:\test\folder\file.txt :\test\folder\file.txt

the drive letter is missing on the destination.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:18:35+00:00Added an answer on May 29, 2026 at 9:18 am

    I believe SetLocal EnableDelayedExpansion is needed along with its counterpart ! replacement of % in variable expansion to get your code to work.

    I am away from my Windows machine right now, so I cannot test the syntax, but off the top of my head, something like this should work:

    SetLocal EnableDelayedExpansion
    @echo off
    set drive=c    
    set ready_to_move=0  
    set file_list=e:\test\files.txt
    
    if "!ready_to_move!" == "1" (
      set echo=
    ) else (
      set echo=echo
    )
    
    for /F "eol=; tokens=1 delims=" %%f in ('type "!file_list!"') do (
      set source=%%~f
      for /f "tokens=* delims= " %%s in ("!source!") do set source=%%s
      set destination=!drive!!source:~1!
      !echo! xcopy "!source!" "!destination!"
    )
    

    Does this work for you?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a persistent windows service in java that runs on boot. I
I have a function that lets me write the file-path of files to a
I inherited a problem. I have a Windows 2003 machine that will not boot.
I have Windows File sharing enabled on an OS X 10.4 computer. It's accessible
I have windows forms application wich runs another console application here is the part
I'm looking to have windows recognize that certain folders are associated to my application
I have a C++ Win32 application that was written as a Windows GUI project,
I have a Windows service running in local system that simply keeps trying to
I have this C# app which starts at system boot in the tray, and
I have a dual boot system with Windows and Linux. I have another partition

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.