Copy only directories from a command prompt - cmd

I want to copy only directories (it's files and sub directories) within the current directory from a command prompt.
I've already copied all the files in the current directory using this command.
copy * d:\copyfolder
I've tried these for individual folders. To copy a folder:
XCOPY C:\utils D:\Backup\utils /i
To copy a folder including all subfolders.
XCOPY C:\utils* D:\Backup\utils /s /i
But couldn't find a way to copy only directories.

From the command line this should work to copy all folders with subdirectories and files:
for /d %a in (*) do xcopy "%a\*.*" "d:\copyfolder\%a\" /s/h/e/k/f/c

I've tried these for individual folders.
To copy a folder:
XCOPY C:\utils D:\Backup\utils /i
To copy a folder including all subfolders.
XCOPY C:\utils\* D:\Backup\utils /s /i
But this command can help, not overwriting any files.
XCOPY C:\utils\* D:\Backup\utils /s /i /d

Related

Copy files from a source folder that contains the same filenames as the destination folder

I have a folder of music files that I have added/updated ID3 tags (the source folder). I also have another folder containing some of these files (the destination folder), and I want to overwrite/update these by copying only files from the source folder that exists in the destination folder.
I tried using this xcopy command, which does the job it seems as it copies only files that exist in destination folder. But upon inspection, the relevant files in the destination folder are still the old ones which do not have ID3 tags. I cannot figure out why the copied files did not overwrite the old files:
cd /d "C:\Users\lenovo\Desktop\source"
for %x in (*) do xcopy "%x" "C:\Users\lenovo\Desktop\destination" /L /U /Y /I
xcopy /? says about the /L switch:
/L Displays files that would be copied.
However, by https://ss64.com/nt/xcopy.html:
/L List only - Display files that would be copied.
The latter is right!
Removing the /L option weirdly fixed the problem. The files were now correctly copied:
cd /d "C:\Users\lenovo\Desktop\source"
for %x in (*) do xcopy "%x" "C:\Users\lenovo\Desktop\destination" /U /Y /I

How remove all files and folders in the folder except one folder in cmd?

I have problem. I need remove files except one folder. Then create folder and copy files in folder. I used this script:
rd /s /q %1
mkdir %1
xcopy /s /i %2\* %1
But it deleted all files. How I can rewrite this script?

Copying files from a CD to hard drive, then run Java

I'm trying to have a bat inside the CD that will copy the Folder 'src' to desktop.
How can I get the files to copy to a directory, like the desktop, and then run the Java command?
xcopy /s/e /y c:\Desktop\Game \src
cd c:\Desktop\Game
java com/brackeen/javagamebook/tilegame/GameManager
#SET $source=*Your source path*
#SET $destination=*Your destination path*
#xcopy "%$source%" "%$destination%" /E /I /R /Y /Z
#IF ERRORLEVEL 1 ECHO Copy failed. && GOTO :EOF
#CD /D "%$destination%"
#*Start your java command*
Xcopy parameters used :
/E Copy folders and subfolders, including Empty folders
/I Assume the destination is a folder when the destination does not exist
/R Overwrite read-only files.
/Y Suppress prompt to confirm overwriting a file.
/Z Copy files in restartable mode.
More at SS64.com

Script: How to copy/move folders dynamically in Windows using commands

I am having a source folder which has folders (say A,B,C) that i should copy to my destination folder, But while copying if my destination folder has a folder say A, then that folder should not be copied, other two folders should be copied to the destination folder.
I myself found a solution for this.
I use XCOPY with the following parameters: /D /Y /R /H /s /i.
E.g.:
xcopy source destination /D /Y /R /H /s /i

How do I write a batch script that copies one directory to another, replaces old files?

I'd like a batch script in Windows with which I can copy one directory to another. If this directory already exists, and then for each file that already exists in both with the same name and location, it should be overwritten, if it does not exists, it should just be added.
In the end it should be a batch script to which I can pass 2 arguments, source & destination.
In your batch file do this
set source=C:\Users\Habib\test
set destination=C:\Users\Habib\testdest\
xcopy %source% %destination% /y
If you want to copy the sub directories including empty directories then do:
xcopy %source% %destination% /E /y
If you only want to copy sub directories and not empty directories then use /s like:
xcopy %source% %destination% /s /y
It seems that the latest function for this in windows 7 is robocopy.
Usage example:
robocopy <source> <destination> /e /xf <file to exclude> <another file>
/e copies subdirectories including empty ones, /xf excludes certain files from being copied.
More options here: http://technet.microsoft.com/en-us/library/cc733145(v=ws.10).aspx
Have you considered using the "xcopy" command?
The xcopy command will do all that for you.
Try this:
xcopy %1 %2 /y /e
The %1 and %2 are the source and destination arguments you pass to the batch file. i.e. C:\MyBatchFile.bat C:\CopyMe D:\ToHere
Just use xcopy /y source destination

Resources