3

I am using below code to transfer files, it is showing on each movement of file that 1 file(s) moved, 1 file(s) moved and so on...but it is not showing at the end that total number of files moved ? it was working for my first code even echo %%i was placed in the same location as placed below...plz help...?

setlocal enabledelayedexpansion
if exist C:\Hi\*.pdf (goto COPYFILES) else (goto NOFILES)

:COPYFILES
for /f %%i in ('DIR /b C:\Hi\*_*.*') do (
    echo %%i
    set fn=%%i
    set fn=!fn:~11,8!
    move C:\Hi\%%i E:\!fn!\
)
echo complete

:NOFILES
echo There are no files to move
2
  • Would using PowerShell instead of cmd batch be an option for you? Commented Jul 20, 2011 at 11:37
  • Did you try a different approach? Commented Jul 20, 2011 at 13:16

1 Answer 1

1

The variable %%i will only ever contain part of the file name, so you try to

move C:\Hi\30072011.pdf 

instead of

move c:\hi\1000225013_30072011.pdf

Alternative:

setlocal enabledelayedexpansion
if exist C:\Hi\*.pdf (goto COPYFILES) else (goto NOFILES)

:COPYFILES
for /f %%i in ('DIR /b C:\Hi\*_*.*') do (
    echo %%i
    set fn=%%i
    set fn=!fn:~11,8!
    move C:\Hi\%%i E:\!fn!\
)
echo complete
goto:eof

:NOFILES
echo There are no files to move
Sign up to request clarification or add additional context in comments.

2 Comments

Hi Alex, it is not working on my side, no output shown, screen just vanished each time and there is no movement on files.
Also, I have updated the code which I was using firstly. Previous one was wrongly uploaded.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.