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
Related
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
I have a folder That has subfolders as below : I was able to loop and copy the folder and subfolders from test1 to test 3. But I want to extend the functionality by removing the each folder after copying
but am not able to instead is removing all the test 1 to test 3 folder.The test folder is just an example, the folders can be any name.
"C:\BACKUP_FDM_FILES\localbackup\test1"
"C:\BACKUP_FDM_FILES\localbackup\test2"
"C:\BACKUP_FDM_FILES\localbackup\test3"
pushd "C:\BACKUP_FDM_FILES"
for /f "tokens=*" %%G in ('dir /b /s /a:d ') do (
echo Found %%G
XCOPY %%G "C:\FDM\Upload" /e /s /y
if errorlevel 0 (
echo Copy succesffully copied reason Files were copied without error and you can delete the content folder
rd "%%G\*" /s /q
mkdir "%%G"
)
)
popD
pause
If you resort to XCOPY, why not use the "successor" ROBOCOPY without any loop, deleting and re-creating the folder? Like in
robocopy "C:\BACKUP_FDM_FILES\localbackup\" "C:\FDM\Upload\localbackup" /s /e /COPYALL /dcopy:T /move
This will even keep the timestamp on the moved folder, and all attributes on moved files. Added benefit: you can use all the other helpful options of this command at no extra cost.
"C:\BACKUP_FDM_FILES\localbackup\test1"
"C:\BACKUP_FDM_FILES\localbackup\test2"
"C:\BACKUP_FDM_FILES\localbackup\test3"
pushd "C:\BACKUP_FDM_FILES"
for /f "tokens=*" %%G in ('dir /b /s /a:d ') do (
echo Found %%G
XCOPY %%G "C:\FDM\Upload" /e /s /y
if errorlevel 0 (
echo Successfully copied now you can delete folder
popd
rd "%%G\*" /s /q
mkdir "%%G"
)
pause
You are using pushd to go to backup folder so you need to use popd to go back to parent folder.
SS64 - POPD
#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).
Basically what I'm trying to do is make a batch file that will run through the computer and grab everything from the Desktops and My Documents of ever user on the computer. Thing is, I won't know every users name because it will be used on unknown computers to back up. Trying to find a way to copy these things but so far I can not. I've been working on My Documents and I keep getting a "Invalid number of parameters".
#echo off
echo This script will copy all of the files from my documents onto a C drive.
pause
md "C:\TestForWork"
pause
for /D /r %%G in ("C:\Users") DO for /D /r "%%H" in ("%%G\My Documents\") do xcopy %%H /e /y "C:\TestFor Work"
pause
for /d %%u in ("c:\users\*") do for %%f in ("Desktop" "Documents") do (
robocopy "%%~u\%%~f" "c:\test for work\%%~u\%%~f" /s
)
Or, for xcopy
for /d %%u in ("c:\users\*") do for %%f in ("Desktop" "Documents") do (
xcopy "%%~u\%%~f" "c:\test for work\%%~u\%%~f" /e /y /i
)
You need to enclose the first parameter to xcopy in double-quotes because it is a directory name containing spaces:
for /D /r %%G in ("C:\Users") DO (
for /D /r %%H in ("%%~G\My Documents\") do (
xcopy "%%~H" /e /y "C:\TestFor Work"
)
)
You also need to use the ~ to prevent double-quotes from being included in the variable expansion.
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 *