1

I have a text file containing file paths for files that I need to upload, ex:

F:\Folder\Sub\file.ext

I was able to find a script that puts all of the files into a destination folder, but I can't seem to modify it to wrap it in its containing folder. I tried the script I found here, but it doesn't seem to work or throw any errors, and I'm too green to figure it out without spending hours teaching myself. Hoping someone can help me modify the script I used

@Echo Off
cls
set dest=C:\filestoupload
set i=1
for /f %%f in (imfcheckmassaged.txt) do (
    for /f "tokens=*" %%F in ('dir /S /B /A:-D "%%f"') Do (
        xcopy /S/E "%%F" "%dest%"
    )
)
Community
  • 1
  • 1
yungkory
  • 11
  • 1
  • Just a note to say that using subdirectory options, **`/S`**, to both `dir` and `xcopy` appears to be counterproductive. Use one or the other. – Compo Feb 28 '17 at 10:22

1 Answers1

0
@Echo Off
cls
set "dest=C:\filestoupload"
set "i=1"

rem take all non-empty lines from file `imfcheckmassaged.txt`
rem     for instance `F:\Folder\Sub\file.ext`
for /f "tokens=*" %%f in (imfcheckmassaged.txt) do (

    rem find `file.ext` in the folder `F:\Folder\Sub\` 
    rem                 (and all occurrences in its subdirectories, note /S switch)
    rem                  for instance `F:\Folder\Sub\file.ext`
    rem                           and `F:\Folder\Sub\Sub2\file.ext`
    rem                           and `F:\Folder\Sub\Sub2\Sub3\file.ext`
    for /f "tokens=*" %%F in ('dir /S /B /A:-D "%%~f" 2^>NUL') Do (

        rem copy them into the ˙%dest%˙ folder including folder structure
        xcopy "%%~F" "%dest%\%~pF"
    )
)

Above code snippet would result to following (full path) file structure (according to examples given in rem comments):

C:\filestoupload\Folder\Sub\file.ext
C:\filestoupload\Folder\Sub\Sub2\file.ext
C:\filestoupload\Folder\Sub\Sub2\Sub3\file.ext

Resources (required reading):

JosefZ
  • 28,460
  • 5
  • 44
  • 83