I just try move all directories from directory "D:\Download" to "D:\DownloadArchive"
I try this but doesnt work
move /y "D:\Download\*.*" "D:\DownloadArchive"
Use "FOR /D" to select only directories. (Disclaimer: untested)
FOR /d %1 IN ("D:\Download\*") DO move /y "%1" "D:\DownloadArchive"
A very simple solution is to use a FOR statement to move each file in the directory. A better alternative to move is xcopy as it allows to over-wright existing files.
For the switches I'm using type xcopy /? in an CMD Window.
From Batch:
FOR /d %%i IN ("D:\Download\*") DO xcopy "%%i" "D:\DownloadArchive" /E /I /Y /S
From CMD:
FOR /d %i IN ("D:\Download\*") DO xcopy "%i" "D:\DownloadArchive" /E /I /Y /S
Related
#echo on
cls
set "root"="%CD%"
cd bin\cemu*
xcopy /q .\mlc01\* "%root%\temp\mlc01\" /e /i /y
xcopy /q .\hfiomlc01\* "%root%\temp\hfiomlc01\" /e /i /y
cd ..
rmdir /s /q cemu_1.7.3d
rmdir /s /q cemu_1.7.4d
cd ..
cd bin\cemu*
xcopy /q "%root%\temp\" .\mlc01\* /e /i /y
xcopy /q "%root%\temp\" .\hfiomlc01\* /e /i /y
cd "%root%"
pause
everything works fine with changing directories and everything but xcopy isn't copying directories or anything (I used this same command in my other project to and it works fine but here it wont)
I tried /s /t /e and all that stuff and I still cant get it going
Try changing:
set "root"="%CD%"
to:
set "root=%CD%"
Due to the quirks that exist in cmd.exe's quoting (cmd.exe has so many quirks) the first variation doesn't do what you want it it to do - it creates an environment variable named root" (yes, the environment variable name has a trailing double-quote character).
I want to copy folder IMAGE to all other folders in a folder.
The folder structure is:
Test folder
FirstSubFolder
IMAGE
OneMoreSubFolder
Test Folder 1
TestFolder2
The result should be:
Test folder
FirstSubFolder
IMAGE
IMAGE
OneMoreSubFolder
IMAGE
Test Folder 1
IMAGE
TestFolder2
IMAGE
Which commands do I need in a batch script to do this folder copying task?
With Test folder being the current directory use following batch code:
#echo off
for /D %%D in (*) do (
if /I not "%%D" == "IMAGE" (
xcopy "IMAGE\*" "%%D\IMAGE\" /C /E /H /I /K /Q /R /Y >nul
)
)
Or if just the files and subfolders in IMAGE should be copied to all other subfolders of Test folder, use this code:
#echo off
for /D %%D in (*) do (
if /I not "%%D" == "IMAGE" (
xcopy "IMAGE\*" "%%D\" /C /E /H /I /K /Q /R /Y >nul
)
)
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
echo /?
for /?
if /?
xcopy /?
What do I add to my DEL batch file if I want to exclude a folder inside a folder I want to delete?
I have this code to delete my all the contents of the temp folder
DEL /F /Q C:\temp
Now, I want to exclude a folder named imptfolder inside. This shouldn't be deleted whether it exists or not inside the temp folder. How do I do this?
Here's some batch script code that'll do what you're asking.
for /d %%I in (c:\temp\*) do (
if /i not "%%~nxI" equ "imptfolder" rmdir /q /s "%%~I"
)
del /q c:\temp\*
If you're just entering these commands from the console, use single percents rather than double.
cd /d c:\temp
for /d %I in (*) do #(if /i not "%~I" equ "imptfolder" rmdir /q /s "%~I")
del /q *
I have a folder with some content which I want to copy into 260 folders, which all are in the same folder.
I guess this is doable with a batch file and a for-loop, but I can't seem to understand how to do it.
you can use XCopy for copy the file
xcopy "src\*.*" "..\..\..\dst" /s /i /c /y
and can add the loop FOR loop
for /l %%a in (1,1,260) do (
call :Method1
)
:Method1
xcopy "src\*.*" "..\..\..\dst" /s /i /c /y
GOTO :EOF
Update
FOR /D %%a in ("dst\*") do
xcopy "src\*.*" "%%a" /s /i /c /y
I have checked some examples on internet but I can't get my (first) batch file to work. I would like to copy automatically my file from a folder to another one but nothing happen.
#echo off
xcopy "C:\source\" "C:\target\" /c /d /i /y
exit
Could you see anything wrong?
Thanks!!
Update: I have done the command given by Bali C but it still doesn't work. See snapshot
xcopy C:\folder1 C:\folder2\folder1 /t /e /i /y
xcopy C:\folder1 C:\folder2\ /t /e /i /y
Image:
I have to stop it with CTRL + C.
PS: I'm on Win 7
Update (Solution):
It works! The problem was the name xcopy,bat on my Desktop, and I was running the command from there, so it was executing the xcopy.bat file of my desktop instead of the Windows one.. I had to rename the file with "myxcopy.bat" :
#echo off
xcopy "C:\source" "C:\target" /c /d /i /y
exit
After testing most of the switches this worked for me:
xcopy C:\folder1 C:\folder2\folder1 /t /e /i /y
This will copy the folder folder1 into the folder folder2. So the directory tree would look like:
C:
Folder1
Folder2
Folder1
Based on xcopy help, I tried and found that following works perfectly for me (tried on Win 7)
xcopy C:\folder1 C:\folder2\folder1 /E /C /I /Q /G /H /R /K /Y /Z /J
If the requirement is to copy all files in "\Publish\Appfolder" into the parent "\Publish\" folder (inclusive of any subfolders, following works for me)
The switch '/s' allows copying of all subfolders, recursively.
xcopy src\main\Publish\Appfolder\*.* /s src\main\Publish\
You must specify your file in the copy:
xcopy C:\source\myfile.txt C:\target
Or if you want to copy all txt files for example
xcopy C:\source\*.txt C:\target