I need to batch copy two folders, let's call them A and B, from F:\Sourcefolder\ to F:\destinationfolder subfolders (not to destination folder itself).
Now I know when batch copying file (file.exe for example) it is supposed to look something like this
for /r "F:\destinationfolder" %%i in (.) do #copy "F:\Sourcefolder\file.exe" "%i"
In each of those subfolders there is a lot of files. After copying A and B folders to all subfolders, I would like to move all files within the subfolders to folder A within their folder. Is this possible to do?
the XCOPY command is designed for folder copy, FOR /D will list level1 folders:
for /d %%a in ("F:\destinationfolder\*") do (
XCOPY "F:\Sourcefolder\A\*" "%%~fa" /s /i
XCOPY "F:\Sourcefolder\B\*" "%%~fa" /s /i
)
for recursive copy (all subfolders):
for /r /d "F:\destinationfolder\" %%a in (*) do (
XCOPY "F:\Sourcefolder\A\*" "%%~fa" /s /i
XCOPY "F:\Sourcefolder\B\*" "%%~fa" /s /i
)
FOR /R will not work properly if there's no wildcard in the brackets - ? or *
ROBOCOPY,XCOPY
Related
S:
cd \newclients
xcopy "s:\clients\*\MER" . /s /d
pause
This is my batch file. In my folder tree we have clients then names folders then MER folder. I want to be able to search the directory for the MER folder and copy that folder along with the client name before it. Is there a way to do this with batch files?
Using if exist should do the thing.
pushd "s:\newclients"
for /f "delims=" %%f in ('dir /b /ad "s:\clients\*"') do (
if exist "s:\clients\%%f\MER\nul" ( xcopy "s:\clients\%%f\MER" "s:\newclients" /s /d )
)
popd
pause
Note: Add a slash if it's to check folder ie. if exist "s:\clients\%%f\MER\" ... or if exist "s:\clients\%%f\MER\nul" ...
To suppress prompt about destination file/folder add /I in xcopy :
/I If in doubt always assume the destination is a folder
e.g. when the destination does not exist.
https://stackoverflow.com/a/33445866/
I am trying to run a simple xcopy batch script but I am facing some difficoulties.
Here is the script
SET SRC=C:\FOLDER1\FOLDER2
SET DEST=V:\FOLDER1
FOR /D %%d in (%SRC%\*) do xcopy /S /I /y /exclude:%SRC%\exclude.txt %%d V:\FOLDER1\%%~nxd
Basically this script should copy some of the subfolders of C:\FOLDER1\FOLDER2 (excluded.txt contains a list of directories to exclude) and its content to the destination. However when I run the scripts, altough no errors are thrown, NO FILES OR FOLDERS get copied. What am I doing wrong?
Interestingly if I run the following script INSIDE FOLDER2, everything procedes as expected.
FOR /D %%A in (*) DO xcopy /S /I /y /exclude:exclude.txt %%A V:\FOLDER1\%%A
xcopy "C:\FOLDER1\FOLDER2" "V:\FOLDER1" /e /i /y
You mention nothing about excluding any folders.
I have a directory called Case Files, and within it many directories labled:
Defendant 1
Defendant x
Defendant 88
Defendant !!
etc...
(btw these folders are the defendants names, they're not actually labeled 'defendant')
In each of the Defendant folders is a directory called Pleadings. Is there a way I can copy filexxxx.pdf into the Pleadings folder for each defendant? Preferably I would like to just run a simple .bat if possible.
This should copy the pdf into every folder called pleadings under c:\case files
#echo off
for /d /r "c:\case files" %%a in (*) do (
if /i "%%~nxa"=="pleadings" copy /y "c:\folder\file.pdf" "%%a"
)
pause
#echo off
cd /d "c:\case files"
for /r %%d in (~) do (
echo %%d | find /i "\Pleadings\~" >nul 2>&1 && copy /y "c:\filexxxx.pdf" "%%~dpd\"
)
Try this from within the Case Files directory:
FOR /F "usebackq delims==" %i IN (`dir /s /b Pleadings`) do copy /y filexxxx.pdf %i
But check my comment because I have a feeling that's not exactly what you're looking for.
Here is my folder hierarchy:
[Numbers]
[Numbers/12545]
[Numbers/12545/dev]
[Numbers/12545/prod]
[Numbers/32445]
[Numbers/32445/dev]
[Numbers/32445/prod]
...
[Numbers/.....]
[Numbers/...../dev]
[Numbers/...../prod]
I want to copy some text files under the only "[Numbers/...../dev]" folders. How should i do?
I tried the below code and it's not work because it coppies under the all subfolders.
for /r %NUMBER_DIRS% %%d in (.) do (
copy %PROJECT_INPUTS%\*.txt "%%d"
)
Thanks.
Try this:
for /d /r "%NUMBER_DIRS%" %%d in (*DEV) do copy "%PROJECT_INPUTS%\*.txt" "%%~d\*.txt"
#ECHO OFF
SETLOCAL
FOR /f "delims=" %%i IN (
'dir /s /b /a:d "\numbers" ^| findstr /i /e "\dev"'
) do ECHO COPY %PROJECT_INPUTS%\*.txt "%%i\"
This will report what the batch PROPOSES to do. Remove the ECHO keyword before the COPY to execute the copy.
Note : you may need to add /y to the copy options if you want to OVERWRITE an existing file in the destination directories.
I presume that you're copying FROM %PROJECT_INPUTS% TO many ...\dev directories.
I'm trying to delete all .svn folders ONLY if they are in a CVS folder. The pattern should be something like this "*CVS\.svn".
However, my attempts at writing a batch script at this is not working at the moment. Here is what I have so far although it doesn't work.
FOR /D /R %%X IN (*CVS\.svn) DO RD /S /Q "%%X"
or
FOR /R CVS %%X IN (.svn) DO (RD /S /Q "%%X")
This works if you start one level higher than the "CVS" directory (it's a little more complex otherwise):
for /f %d in ('dir /a:d /b /s CVS') do (
if exist "%d\.svn\." rd /s /q "%d\.svn"
)
The first line finds all the directories named "CVS" recursively, then the second deletes the sub-directory ".svn" if it exists. If you're running it from a batch/shell script, use %%d instead of %d.