How to copy a folder with the given input

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
dheerajreddy926
Posts: 5
Joined: 19 Apr 2012 07:39

How to copy a folder with the given input

#1 Post by dheerajreddy926 » 19 Apr 2012 07:50

Hello All,

I am new here .I am struggling to find a solution.

I need a batch script to copy a folder which is in the form XXXXX_YYYYYYYY

Eg: i want to copy folder 2011.50.00++22.00_2011-11-23_6-08-43_PM to another folder .For this i want to give input as 2011.50.00++22.00 which is unique .

I have written a batch file but its not copying the folder.

ECHO off
cls
SET /P RN=enter release number eg : 2012.20.00++22.01 :
ECHO %RN%
d:
cd D:\backup\PUSHED

XCOPY %RN%* \\r1mseac02\d$\sea77\siebsrvr\LOGARCHIVE\ /S

%SystemRoot%\explorer.exe "\\r1mseac02\d$\sea77\siebsrvr\LOGARCHIVE\ "

pause

ECHO ON

------------------------------------------------------------------

the folder i wanna copy will be in D:\backup\PUSHED

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: How to copy a folder with the given input

#2 Post by foxidrive » 19 Apr 2012 08:13

Untested:

Code: Select all

@ECHO off
cls
set "RN="
SET /P "RN=enter release number eg : 2012.20.00++22.01 :"
ECHO %RN%
pushd "D:\backup\PUSHED"
XCOPY "%RN%\*.*" "\\r1mseac02\d$\sea77\siebsrvr\LOGARCHIVE\" /S
"%SystemRoot%\explorer.exe" "\\r1mseac02\d$\sea77\siebsrvr\LOGARCHIVE\"
popd
pause


With some extra code you can automate the copy by getting the folder name - if there is the one folder in the directory or you can specify the folder in a DIR command.

dheerajreddy926
Posts: 5
Joined: 19 Apr 2012 07:39

Re: How to copy a folder with the given input

#3 Post by dheerajreddy926 » 19 Apr 2012 09:37

Hi

I dint solve my problem :(

what is got from ur code is like it will copy the items which are after the folder %RN%

but %RN% is not the entire folder name.

for ex 2012.20.30_rhdhkdn is the folder i wanna give input as 2012.20.30 and thescript should copy the folder whose folder name starts with 2012.20.30 ie 2012.20.30_rhdhkdn to the destination folder

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: How to copy a folder with the given input

#4 Post by foxidrive » 19 Apr 2012 10:37

This should copy the folder.

Code: Select all

@echo off
cls
set "RN="
SET /P "RN=enter release number eg : 2012.20.00++22.01 :"
pushd "D:\backup\PUSHED"
for /f "delims=" %%a in ('dir "%rn%*" /b /ad') do (
echo copying "%%a"
XCOPY "%%a\*.*" "\\r1mseac02\d$\sea77\siebsrvr\LOGARCHIVE\" /S
)
popd
"%SystemRoot%\explorer.exe" "\\r1mseac02\d$\sea77\siebsrvr\LOGARCHIVE\"
pause

dheerajreddy926
Posts: 5
Joined: 19 Apr 2012 07:39

Re: How to copy a folder with the given input

#5 Post by dheerajreddy926 » 19 Apr 2012 11:10

I tested the code in my local laptop.

enter release number eg : 2012.20.00++22.01 :2012.20.00++22.00
copying "2012.20.00++22.00_yyjdkd"
Overwrite C:\test3\1\New Text Document.txt (Yes/No/All)? y
2012.20.00++22.00_yyjdkd\1\New Text Document.txt
1 File(s) copied
Press any key to continue . . .

C:\Users\velumula\Desktop>


Its copying if the name given as a ipnput is a file .If its a folder its not copying to destination folder.

dheerajreddy926
Posts: 5
Joined: 19 Apr 2012 07:39

Re: How to copy a folder with the given input

#6 Post by dheerajreddy926 » 19 Apr 2012 11:23

@echo off
cls
set "RN="
SET /P "RN=enter release number eg : 2012.20.00++22.01 :"
pushd "C:\test1"
for /f "delims=" %%a in ('dir "%rn%*" /b /ad') do (
echo copying "%%a"
XCOPY "%%a" "C:\test3\" /T /E
)
popd
REM "%SystemRoot%\explorer.exe" "\\r1mseac02\d$\sea77\siebsrvr\LOGARCHIVE\"
pause


WHEN I USE /T /E its copying subfolders in the input fiolder to destination.I need even the folder to copy to destination with subfolders.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: How to copy a folder with the given input

#7 Post by foxidrive » 19 Apr 2012 12:58

I'm not sure what you are after. This should only copy that folder if the name is unique.

This should include the folder name in the target folder.

Code: Select all

@echo off
cls
set "RN="
SET /P "RN=enter release number eg : 2012.20.00++22.01 :"
pushd "D:\backup\PUSHED"
for /f "delims=" %%a in ('dir "%rn%*" /b /ad') do (
echo copying "%%a"
XCOPY "%%a\*.*" "\\r1mseac02\d$\sea77\siebsrvr\LOGARCHIVE\%%a\" /S/H/E/K/F/C/R/Y
)
popd
"%SystemRoot%\explorer.exe" "\\r1mseac02\d$\sea77\siebsrvr\LOGARCHIVE\"
pause

dheerajreddy926
Posts: 5
Joined: 19 Apr 2012 07:39

Re: How to copy a folder with the given input

#8 Post by dheerajreddy926 » 19 Apr 2012 13:46

while tryn in my local i dint give %%a at the end of destination folder ... now i m successful in copying..thanks mate :)

Post Reply