xcopy "C:\SomeFolderName" "D:\SomeFolderName" /h /i /c /k /e /r /y
Use the above command. It will definitely work.
In this command data will be copied from c:\ to D:, even folders and system files as well. Here's what the flags do:
/hcopies hidden and system files also/iif destination does not exist and copying more than one file, assume that destination must be a directory/ccontinue copying even if error occurs/kcopies attributes/ecopies directories and subdirectories, including empty ones/roverwrites read-only files/ysuppress prompting to confirm whether you want to overwrite a file/zCopies over a network in restartable mode.
Answer from SHABAZ KHAN on Stack Overflowmore flags are found here https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/xcopy
xcopy "C:\SomeFolderName" "D:\SomeFolderName" /h /i /c /k /e /r /y
Use the above command. It will definitely work.
In this command data will be copied from c:\ to D:, even folders and system files as well. Here's what the flags do:
/hcopies hidden and system files also/iif destination does not exist and copying more than one file, assume that destination must be a directory/ccontinue copying even if error occurs/kcopies attributes/ecopies directories and subdirectories, including empty ones/roverwrites read-only files/ysuppress prompting to confirm whether you want to overwrite a file/zCopies over a network in restartable mode.
more flags are found here https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/xcopy
Use xcopy /s I:\*.* N:\
This is should do.
cp dir1/* dir2
cp will not copy directories unless explicitly told to do so (with --recursive for example, see man cp).
Note 1: cp will most likely exit with a non-zero status, but the files will have been copied anyway. This may be an issue when chaining commands based on exit codes:&&, ||, if cp -r dir1/* dir2; then ..., etc. (Thanks to contrebis for their comment on that issue)
Note 2: cp expects the last parameter to be a single file name or directory. There really should be no wildcard * after the name of the target directory. dir2\* will be expanded by the shell just like dir1\*. Unexpected things will happen:
- If
dir2is empty and depending on your shell and settings:- you may just get an error message, which is the best case scenario.
dir2/*will be taken literally (looking for a file/directory named*), which will probably lead to an error, too, unless*actually exists.dir2/*it will just be removed from the command entirely, leavingcp dir1/*. Which, depending on the expansion ofdir1/*, may even destroy data:- If
dir1/*matches only one file or directory, you will get an error fromcp. - If
dir1/*matches exactly two files, one will be overwritten by the other (Bad). - If
dir/*matches multiple files and the last match is a, you will get an error message. - If the last match of
dir/*is a directory all other matches will be moved into it.
- If
- If
dir2is not empty, it again depends:- If the last match of
dir2/*is a directory,dir1/*and the other matches ofdir2/*will be moved into. - If the last match of
dir2/*is a file, you probably will get an error message, unlessdir1/*matches only one file.
- If the last match of
It's the shell that expands wildcards, not the commands. So cp dir1/* dir2/* first expands the two wildcards, then calls cp on the result. This is not at all what you apparently expect: depending on how many files there are already in dir2, dir2/* may expand to one or more argument. The command cp doesn't know which of its arguments came from expanding the first pattern and which ones came from expanding the second pattern. It expects its last argument to be the name of the destination directory. Thus, to copy all the files from the directory dir1 into the directory dir2, the last argument must be the directory dir2:
cp dir1/* dir2
Since * matches all files, cp attempts to copy all files. This includes directories: directories are files too. It skips directories, but reports an error. It copies the content of special files such as named pipes (something had better be writing to them, or cp will block), etc.
To copy only regular files, you need to restrict the matching. In zsh, you can use the glob qualifier . for that:
cp dir1/*(.) dir2
Other shells don't have this. You can use the find command to filter on file types. Assuming that you're running non-embedded Linux or Cygwin:
find dir1 -maxdepth 1 -type f -exec cp -t dir2 {} +
On Linux, FreeBSD and OSX:
find dir1 -maxdepth 1 -type f | xargs -I {} cp {} dir2
copying all file
How to copy all files recursively into another folder with permission?
Copying all folders and files from one location to another | Access World Forums
Any EASY Way to Move Multiple Files from Multiple Folders to Root Folder?
Videos
You can copy the contents of a folder /source to another existing folder /dest with the command:
cp -a /source/. /dest/
The -a option is an improved recursive option, that preserves all file attributes and symlinks.
The . at end of the source path is a specific cp syntax that copies all files and folders, including hidden ones.
An alternate is rsync:
rsync -a source/ destination
The advantages of rsync are:
- After the initial sync, it will then copy only the files that have changed.
- You can use it over a network, convenient for files in $HOME, especially config files.
Hey,
I wanted to copy all all files from one directory to another, like this:
cp -i /source/. /destination
I knew the source had no subdirectories and I wanted a prompt if files needed to be overwritten.
Now, this didnt work got the error " -r not specified, omitting directory /source/"
It worked with -r. I dont understand why though, there wre
Cheers,
Try using XCOPY with the /E switch. More info here.
I haven't had to access this information from my brain in years!
UPDATE
The documentation says that it copies all files and subdirectories from the source directory (meaning that the parent directory is not created), so you would have to create test in C:\test2 first and then use XCOPY.
xcopy c:\test c:\test2\test /s /e /h
Here is info on XCOPY [1,2]
cp -r /path/to/someDirA/folderTwo /path/to/someDirB/
The -r option to cp tells it to recurse on directories, copying its contents.
You can use cp to copy files and directories:
cp -r /path/to/someDirA/folderTwo /path/to/someDirB
The -r option is needed when copying directories.
Alternatively, you can use rsync:
rsync -a /path/to/someDirA/folderTwo /path/to/someDirB
I normally would use install -Dm755 * --target-directory=/path/to/target. However, this time, the current folder contains directories and install does not support it.
Is there any oneliner I am missing to copy all files and directories of the current folder to /path/to/target with the specified permission (755)?
Technical limitation: I can't use rsync. Thanks, flatpak team! Very helpful.
Ok I used both cp -r and chmod -R manually.
Here's one way I'd tackle the problem:
- Go to common parent of all your pictures. For example, if they're all arranged underneath C:\Users\Joe\Pictures\ , go to that pictures folder where you see all the other month/year folders.
- Type an * (asterisk) into the Search box at the top-right. All files and folders under your current position will be listed. Or if you only wanted pictures, you could type kind:picture (or even *.gif to only get that specific kind of pic and ignore JPG and BMP for example). But an * will get everything.
- Sort by name, which will group all the folders together, and then all the files together as well (in a flat view, regardless of what folder they are really in).
- Select all the photos and drag them into the folder you really want them to be stored in.
- Delete all the now-empty folders.
If you still want to be able to view your pictures by year taken and other attributes without a lot of fuss or even moving them at all, give Windows Live Photo Gallery a try from http://get.live.com. It even has face recognition, so if you tell it who someone is once, it can find them in other pictures automatically.
Shawn, you are heaven sent...thank you, it worked!!!
Try this:
cp Folder1/* Folder2/
Quite simple, with a * wildcard.
cp -r Folder1/* Folder2/
But according to your example recursion is not needed so the following will suffice:
cp Folder1/* Folder2/
EDIT:
Or skip the mkdir Folder2 part and just run:
cp -r Folder1 Folder2
I suggest FreeFileSync, which appears to have the ability to create a script that will automatically sync the two folders every few seconds. I haven't played with it personally, but it looks promising.

Have you considered using RoboCopy? http://ss64.com/nt/robocopy.html
RoboCopy can be set to copy the data after a set period of time has elapsed and/or a number of changes to the datasets have occured.
/MON:n : MONitor source; run again when more than n changes seen.
/MOT:m : MOnitor source; run again in m minutes Time, if changed.