sanam_bl
sanam_bl

Reputation: 329

Batch File Copy contents from one folder to another

I have the following folder structure :

-folder1
 - Folder2
    - Folder3
        -Folder4
            -Folder5
                - Folder6
                - Folder7
                - Folder8
        -Folder9
            -Folder10
                - Some Files
                - package.bat

@echo off
set SOURCE=""
set DESTINATION="oer_distribution\"

REM ZIP app settings:
set ZIP_EXE="C:\Program Files\7-Zip\7z.exe"
set ZIP_EXTENTION=zip
set ZIP_FILE_NAME=oer_distribution
set EXTRACT_KEY=x
set ARCHIVE_KEY=a
set FOLDER_TO_ZIP=oer_distribution
set ZIP_FILE_NAME=%ZIP_FILE_NAME%.%ZIP_EXTENTION%


:CREATE_FOLDER
echo ************************************************************
IF exist %DESTINATION% (
RMDIR /Q /S %DESTINATION%
echo %DESTINATION% deleted
)
mkdir %DESTINATION%
echo %DESTINATION% created

:COPY_CONTENTS
echo --------------------------------------------------------
 xcopy %SOURCE% %DESTINATION% /E
 echo contents copied from %SOURCE% to %DESTINATION%

:CREATE_ZIP
echo --------------------------------------------------------
echo Create ZIP file for distribute....
if exist %ZIP_FILE_NAME% del %ZIP_FILE_NAME%
rem "C:\Program Files\7-Zip\7z.exe" a "Folder2.zip" %DESTINATION%
%ZIP_EXE% %ARCHIVE_KEY% %ZIP_FILE_NAME% %FOLDER_TO_ZIP%\
echo zip file created


:DELETE_FOLDER
echo """"""""""""""""""""""""""""""""""""""""""""""""""""""""
RMDIR /Q /S %DESTINATION%
echo %DESTINATION% deleted

Now when I run the batch file from Folder10(package.bat) it has to copy all the contents from folder5, create a new Folder11 under Folder10 and copy the contents there.

My main problem is how to define the source and destination path.

Thanks

Upvotes: 0

Views: 884

Answers (1)

Jason Faulkner
Jason Faulkner

Reputation: 6598

It appears your question is how to create the appropriate relative path to get from Folder10 (which is your current directory) to Folder5 and copy this to a new Folder11 beneath Folder10.

This being the case, you could just do this:

SET Source="..\..\Folder4\Folder5"

The ..\ will back up one level from the current directory, so this command moves like so:

Folder10 (current) > Folder9 (..\) > Folder3 (..\) > Folder4 > Folder5

It appears you already have the code to copy Source to Destination so the above path should do it.

Upvotes: 1

Related Questions