Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm currently trying to create a batch file, which actually copy a folder from a server to a clients machine. And I'm playing around with batch file, using xcopy, and it gives me the percentage of completion. I'm not a programmer, i just modified a tiny mount of lines from a code which i got from: https://answers.yahoo.com/question/index?qid=20120229012108AA8EwOA (all credit goes to "Jake").

However, the batch file will actually copied the whole files, including the parent folders, did i miss something here?

Here is the code:

@echo off&color a
setlocal enabledelayedexpansion

cd /
mkdir ZZZDestination
set startdir="C:\ZZZSource\Depth1\Depth2\the files"
set enddir="C:\ZZZDestination\"
echo.
echo Please make sure you are connected to Ericsson Network-preferrably via LAN CABLE
echo This will copy the files to your machine
echo.
echo Press any key to continue
PAUSE>nul

for /f "tokens=1,2,3,4,5" %%a in ('dir /s %startdir%^|findstr bytes') do if /i not "%%e"=="free" set qtyfiles=%%a
set filecount=0
for /f "tokens=*" %%a in ('dir /a-d-h-s /s /b %startdir%') do (
xcopy /z /q /s /e /y "%%a" "%enddir%\%%~pa\*.*" >nul
set /a filecount=!filecount!+1
set /a percentage=!filecount!*100 / !qtyfiles!
cls
echo.
echo Copying files, PLEASE DO NOT CLOSE THIS WINDOW
echo ======================================================
echo Please wait for copying:       !percentage!%% Completed
echo ======================================================
)
echo.
echo DONE, please press any key to exit..
PAUSE>nul

I have tried to modified the xcopy /z /q /s /e /y "%%a" "%enddir%\%%~pa*.*" >nul into xcopy /z /q /s /e /y "%%a" "%enddir%" >nul However, the files inside the subfolder under C:\ZZZSource\Depth1\Depth2\the files will be copied out from the folder. For example, under folder C:\ZZZSource\Depth1\Depth2\the files, there are folder A B C, and inside those, there are each 4-5 files. Those 4-5 files, will all be copied out into "C:\ZZZDestination\".

Anyone have any idea?

Thank you in advance.

share|improve this question
1  
Can you describe the results you are looking to achieve? –  BrianAdkins Apr 18 at 10:53
    
I'm expecting the content inside "the files" in "C:\ZZZSource\Depth1\Depth2\the files" to be copied into "C:\ZZZDestination\" without any changes of the file/folder structure nor copying the parent folders. so now, as result what i got is: "C:\ZZZDestination\ZZZSource\Depth1\Depth2\the files\", whilst what I need and I expect: "C:\ZZZDestination\the files\" without compromising the files/folder structure under folder "the files". Hopefully I made myself clear. Thanks alot in advance. –  Satria Apr 20 at 5:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.