i have a batch script that i want it to copy everything inside a specific folder to another but it only copy files it doesn't copy the sub folders.
thanks in advance
Here is how im copying the inside of the folder:
xcopy /s %FILETOZIP% %TEMPDIR%
Using XCOPY, the parameters should be at the end:
XCOPY source [destination] [options]
If any folders are empty and you want to include them, you will need the /E parameter instead.
Try the following to capture the entire directory structure:
xcopy %FILETOZIP% %TEMPDIR% /s /e
Related
I am having the following folder structure:
Folder1
-Folder2
-File1
-File2
-File3
I have tried the following in batch script to copy all inside the Folder1
echo d | xcopy "Folder1\*.*" "DestinationFolder"/f /s /y /r
But I need to copy only File1, File2, File3. Need to ignore Folder2. I don't have any idea about how to achieve this. Please help me resolve this.
If Folder2 is empty, /S will do,
but since you have /s in your command, so I guess it's not empty.
So use this:
echo \Folder2\>__tmp4Exclude__
echo d | xcopy "Folder1\*.*" "DestinationFolder" /f /s /y /r /EXCLUDE:__tmp4Exclude__
del __tmp4Exclude__
__tmp4Exclude__ is a temp file created to contain the list of files to exclude while copying.
From xcopy /?:
/EXCLUDE:file1[+file2][+file3]...
Specifies a list of files containing strings. Each string
should be in a separate line in the files. When any of the
strings match any part of the absolute path of the file to be
copied, that file will be excluded from being copied. For
example, specifying a string like \obj\ or .obj will exclude
all files underneath the directory obj or all files with the
.obj extension respectively.
There is no need to use xcopy to copy just files! xcpoy is usually used to copy directory trees.
So, use copy instead. You can do:
copy "Folder1\*.*" "Destination\"
Probably you may need to use /(-)Y option:
/Y Suppresses prompting to confirm you want to overwrite an existing destination file.
/-Y Causes prompting to confirm you want to overwrite an existing destination file.
From copy /? (copy help page)
I need copy lot of *.txt file from multiple folders to one.
I try use for exp.:
xcopy D:\Dokumenty\*.txt D:\final /sy
But this make 1:1 copy of folder. I need copy only files to a new folder.
Thanks for help.
You can also use wildcard (?*) in ROBOCOPY
usage: ROBOCOPY source destination [file [file]...] [options]
Transposing your example should look like this:
ROBOCOPY "D:\Dokumenty\" "D:\final" *.txt /S
for /r "D:\Dokumenty\" %%# in (*.txt) do copy /y "%%~f#" "D:\final"
I want to move few files and folder available under a source folder to a destination Folder.
I am using :
move /y "%src%\" "%dest%".
This command is just moving files from the source but not the folders.
I need your suggestions. thanks in advance, i will appreciate your efforts.
the command move has no option to move recursively. So you can try to copy recursively with xcopy /s /y and after this delete recursively the source directory with del /s /q. Finally rd /s /q to delete the folders because del will only delete the files.
In my computer, with using command "move /Y src dest", the command works. Windows doesn't support the "move" command if the source folder and destination folder are in different volume. You can have a try.
I am trying to copy a folder and paste it in the same directory it was copied from.
For example
C:\Test is the main directory which consists of a folder ACDM, I would like to copy ACDM in the same directory and rename the new folder to ACDM1 which will have all the same files as ACDM has
I would like to do it using command prompt
I tried the following
C:>Xcopy C:\Test C:\Test\ACDM1 /E /U
Cannot perform a cyclic copy
0 File(s) copied
which fails, not sure hoe to add REN command with XCOPY command.
Need help ASAP as i would want to create a batch file which will create a copy of an existing folder and rename it according to a name retrieved from a text file..
xcopy "C:\Test\ACDM\*.*" "C:\Test\ACDM1\" /s/h/e/k/f/c
for /f "delims=" %%a in (yourtextfilename) do xcopy "C:\Test\ACDM" "C:\Test\%%a\" /E
as a .bat file line. Directly from the prompt, change each %% to %
I've assumed (for lack of futher information) that your textfile contains just the one line
ACDM1
neither do you specify the textfilename tou want to use.
xcopy C:\Test\ACDM C:\Test\ACDM1\ /E /Q
I am trying to create a batch script that copies the contents of one folder into another. Ihave tried this:
mkdir "c:\Jamie"
cd c:\jamie_DateTimeStamp*
xcopy * "c:\Jamie"
for /D %%f in (c\jamie_*) do rmdir %%f /s /Q
I can get the delete to work but I cannot get the xcopy to work.
things to know
The Jamie_datetimestap folder can be any date and time so I don't have a constant and I need to use a wildcard.
The goal of the script to copy the contents of a folder that has a datetime stamp into a folder that does not have one, then delete the folder with the datetime stamp I cannot simply rename the folder.
If you want to copy subfolders with xcopy you need option /s for subdirectories.
You can not use wildcard in cd command though, but you can do a dir /b Jamie* and use this inside the for loop as you do for delete to use as target for cd.