2

I am using this code below to copy files from a list. Everything is working, however doesn't work when files have NO extension. I don't know to fix it.

@echo off
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

SET "src=T:\CNC-Related\CNC Programs\Biesse\Rover346\01 MAIN\S-LINE\SLE"
SET "dst=U:\Users\Edimar\PROJECTS\REPLACE LOCKING BAR\CST640\S-Line\PROGRAM\R346"
SET "file_list=.\files.txt"
SET "out=.\result.log"
echo > %out%

FOR /F "usebackq eol=| delims=" %%f IN ("%file_list%") DO (
    rem just searching to find out existense of file
    WHERE /Q /R %src% "%%f"
    IF "!ERRORLEVEL!" == "0" (
        FOR /F "usebackq eol=| delims=" %%s IN (`WHERE /R %src% "%%f"`) DO (
            echo "%%s => %dst%\%%f" >> %out%
            @Xcopy /y "%%s" "%dst%\%%f" 
        )
    ) ELSE (
        echo %%f is not found! >> %out%
    )
)
lit
  • 14,456
  • 10
  • 65
  • 119
  • Commenting out or deleting the `@echo off` line will allow you to see exactly what commands are being executed. – lit Jul 20 '17 at 00:59
  • I tried the script at my machine and it's working. Nevertheless I would use `copy` instead of `xcopy` because `xcopy` may ask: `Does [...] specify a file name or directory name on the target (F = file, D = directory)?` like it does on my computer. See also here: https://stackoverflow.com/questions/3018289/xcopy-file-rename-suppress-does-xxx-specify-a-file-name-message. Further the line `echo > %out%` does not clear the file but it writes the current state of `echo` in the file. Use `break>%out%` to clear a file. – Andre Kampling Jul 20 '17 at 06:33
  • Hi Andre, I modified my script to uso copy instead of xcopy, but still not working for files without extension. Please see below: U:\Users\Edimar\PROJECTS\REPLACE LOCKING BAR\CST64 rem just searching to find out existense of file WHERE /Q /R T:\CNC-Related\CNC Programs\Biesse\Ro 279R01" IF "!ERRORLEVEL!" == "0" (FOR /F "usebackq eol=| NC-Related\CNC Programs\Biesse\Rover346\01 MAIN\S- echo "%s => U:\Users\Edimar\PROJECTS\REPLACE LOCKI 346\SLE279R01" 1>>.\result.log ) ) ELSE (echo SLE279R01 is not found! 1>>.\resu ) ERROR: The system cannot find the file specified. – Edimar Ferri Jul 20 '17 at 12:41
  • @EdimarFerri Did I just see a bunch of randomly generated, unformatted text in the last comment? All I see is just your `REM`ed the entire code and the error. –  Jul 21 '17 at 00:59

0 Answers0