Copy Directory files to another directory in batch file without asking? - windows

I have created a batch file to copy one folders files to another folder.
This code XCOPY C:\Temp\a.txt C:\Temp2\a.txt /Q works but when i run this file it ask Overwrite C:\Temp2\a.txt (Yes/No/All)?
I want to do this without asking this question. How can i do ? And i want to this for aspx or aspx.cs files

From the manual:
/Y Suppresses prompting to confirm you want to overwrite an existing
destination file
So just add the /Y option in order to overwrite all files without asking.
If you want to copy all files that contain "aspx", you can use
XCOPY C:\Temp\aspx* C:\Temp2\ /Q /Y

You can try this :
XCOPY C:\Temp\a.txt C:\Temp2\a.txt /Q /Y

Related

Batch File Copy and Rename

Currently looking to copy and rename a file from a C:Drive source to a G:Drive destination by using a batch file. Currently have the following code:
robocopy C:\Users\abronk04\Desktop\Test G:\Users\abronk04\Desktop\Backup /e /purge
ren G:\Users\abronk04\Desktop\Backup accessbackup.jpg backup.jpg
The file will successfully copy, but there is no rename. Do I need to specify a file I am looking to rename? My batch file will copy an entire folder to another destination, unsure if that is the problem here...
I think you ren syntax is not correct.
Maybe try the following after copying the directory
pushd G:\Users\abronk04\Desktop\Backup
ren accessbackup.jpg backup.jpg
popd
This way you will temporarily change your working directory to the sink-path and then change it back

Windows xcopy 0 File(s) copied

I am trying to copy a directory but get the following:
xcopy ..\node_modules\ \node_modules\
0 File(s) copied
I run as administrator, but still get the error. Any ideas please?
p.s I actually use the following to stipulate it's a directory. But the above also fails:
echo d | xcopy /d /y ..\node_modules\ \node_modules\
Thanks
You can use the xcopy /E flag to copy the entire directory and subdirectories. Also remove the starting \ of the destination. The trailing slash should prevent the file or directory prompt.
xcopy /E ..\node_modules node_modules\
xcopy ..\node_modules\* \node_modules\
You are specifying the source directory, but not which files to copy.
To copy all the contents like folder, sub-folder or chain of folders we can use below command:
xcopy file-to-copy-path\ where-to-copy-path\ /s /i
/s copies folders and sub-folders
/i If in doubt always assume the destination is a folder e.g. when the destination does not exist.

Batch script to copy folder structure with files skip specific sub-folders

I am trying to copy a folder structure with all data but need to skip folders who have named as 'others'. I created .bat file and trying to move source to destination. I used xcopy /e and exist to check folder but I can't make it. How can I do it?
Use robocopy /E /XD <exclude_file>. See robocopy /? for more options.
create a exclude.txt list into which you can specify which folders or sub folders you want to skip.
use
xcopy "source" "destination" /EXCLUDE:exclude.txt

Windows cmd shell xcopy to network directory doesn't work

Im trying to make a batch file that will copy all new files and folders from a source folder to an network directory. All the new subdirectories and new files should be copied (backup).
My code:
xcopy "C:\Source" "T:\Backup" /d/i/s/q
(/d for only new files, /i because source is a dir, /s for all the subdirs and files, /q just to supress the copy text)
Source contains both subdirectories and files (.txt).
The first run it copies Everything as it should. When I add a new .txt file to one of the existing subdirectories and run it again I get the message:
"An error occured when the file The directory is not empty. was being created.
The folder "T:\Backup" could not be created.
0 files copied.
(Translated from Swedish so not 100% original)
The thing is when I try this command to a local source like e.g. "C:\test" and do the same procedure it works.
Anyone who can understand why this doesn't work for the network drive?
Should I try Another command such as robocopy?
Skip xcopy and use robocopy with the /E flag instead. It's built into all recent versions of Windows. Free download for XP.
Example:
robocopy c:\source T:\backup /E
That will copy all the files in the "source" folder to the "backup" folder that haven't been copied already.
And if you don't want to have the output shown on the console (equivalent to the /Q option in xcopy):
robocopy c:\source T:\backup /E /LOG:nul
Robocopy must be better because it should create directories with the \E switch. No overwrites for files, just adds a file with extra letters or extension <> command. Still must defrag.
XCOPY "DRIVE LETTER:\windows.old\USERS" "\computername\D\NAME\" /D /E /C /R /I /K /Y /f

How to copy files using a batch file? [duplicate]

This question already has answers here:
How do I copy files using Windows Batch?
(6 answers)
Closed 4 years ago.
I need to create a batch file to copy certain files (e.g., 19_1_White.jpg) to a folder within the directory. How can I do this?
XCOPY F:\*.* G:\ /C /S /D /Y /I
XCOPY allows for copying of files, directories, and sub directories.
F:\*.* is our source location
G:\ is our destination location
/C tells XCOPY to ignore errors, and finish what can be done
/S tells XCOPY to copy everything including directories and
subdirectories
/D tells XCOPY to only copy source files that are newer than the
destination files (big time saver on the process)
/Y tells XCOPY to overwrite files without asking for confirmation
/I tells XCOPY to automatically create new directories on the
destination, if new directories were created in source.
you need to use the command XCOPY
eg XCOPY A.jpg C:\Folder\A.jpg
Take a look at https://support.microsoft.com/en-us/help/289483/switches-that-you-can-use-with-xcopy-and-xcopy32-commands for any other switches you may want to use too.

Resources