Batch script to copy files from windows to windows

How to copy the file from one windows machine to another windows machine in a particular drive using batch script?

In my windows server, am taking SQL DB backup in C drive. I wants to copy this .bak file to some other client windows machine in a particular drive with the current date using batch script. So that i can schedule this batch script using scheduled task. please help me out.

Can anyone, give a script to run this. thanks

1 Answer 1

Batch files are always tricky to get just right. First I’d open a command line and see if you can copy between two machines using the following syntax:

(where «remotemachine» is the name of the remote machine and «c$» is the drive you wish to copy to). You can then copy this into a batch file and set up a scheduled task.

As for renaming the file to have the current date and time, I suggest you start with this question as it may involve some effort to get it into a format you want.

Not the answer you’re looking for? Browse other questions tagged windows or ask your own question.

Linked

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.4.16.39093

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Create Script To Copy Files From One Folder To Another On Win10 [MiniTool News]

By Sarah | Follow | Last Updated March 31, 2021

Summary :

The batch script, also known as batch file, actually refers to a list of several commands; whenever you double-click the file, the commands will be executed. If you want to copy files or folders from one folder to another automatically, creating a batch script is a nice choice. As for how to get the work done, please keep reading.

When managing your data on PC, you may need to copy or move files and folders. The permissions set on files and folders may be changed when you move/copy them by using the Windows Explorer. Did you know this?

For instance, when you copy a folder/file in an NTFS partition or from one partition to another, the Windows system will regard it as the new folder/file; in this way, you will become the CREATOR OWNER since the system will take on the permissions. That’s why using script to copy files from one folder to another is necessary.

Читайте также:  Ошибка 0x80072ee2 при активации windows server

Can You Use Script to Copy Files from One Folder to Another

The Windows clipboard provides an easy way for users to copy and paste files/folder manually. The ordinary copy process seems pretty simple: select the file/folder that needs to be copied and choose copy option; open the destination; select the paste option.

Yet, do you want to automatically move files from one folder to another? The copying and pasting process can be finished quickly by using the Windows command line.

What Is Batch File

A batch file, also known as batch script, is actually a list of commands that will be run in the Command Prompt (CMD) tool. Users can create a batch file to let CMD copy and paste files for them automatically; all they need to do is double clicking on the batch file/script and waiting.

How to Use Batch File to Copy Files

How to use Windows script to copy files? Generally, it contains two stages: create batch file and create a task to run the batch file to copy files from one folder to another.

Stage One: Create Batch File

The following steps are finished on a Windows 10 computer.

Step one: click on the Cortana icon on the taskbar (fix taskbar not working on Window 10).

Step two: type notepad into the search text box.

Step three: select Notepad app from the search result by clicking on it.

Step four: type the following script in or copy & paste it into Notepad.

@echo off

set X=

set «source=C:\ «

set «destination=D:\ «

robocopy «%source%» «%destination%» /mov /minage:%X%

exit /b

Of course, the source folder, destination folder, and number of days can be changed due to your needs.

Step five: choose File option from the menu bar and choose Save As… from submenu.

Step six:

  • Give it a name and type in the File name text box; the file name format is .BAT.
  • Select All Files for Save as type option to change the default file type.
  • Click on the Save button at the bottom to finish this step.

Stage Two: Create Task to Run Batch File

After finish this stage, you can use the batch file to copy folder to another location.

Step one: type task scheduler into the Cortana search box.

Step two: choose Task Scheduler from the search result.

Step three: find Actions section from the right-hand panel.

Step four: select Create Task… from the list.

Step five: give a name for the task and type it into the text box after Name.

Step six: shift to Triggers tab and click on the New… button.

Step seven: define the frequency to trigger the task, choosing from One time, Daily, Weekly, and Monthly.

Step eight: set the Start time to decide when the task will be triggered and click on the OK button to confirm.

Step nine: shift to Actions tab and click on the New… button.

Step ten: click on the Browse button to find & choose the .BAT file you have created in stage one.

Step eleven: click on the OK button to confirm. Then, you can close the Task Scheduler and start to move file from one folder to another by using it.

Читайте также:  Windows hangs on desktop

That’s how to use Windows batch to copy file.

ABOUT THE AUTHOR

Position: Columnist

Sarah is working as editor at MiniTool since she was graduated from university, having rich writing experiences. Love to help other people out from computer problems, disk issues, and data loss dilemma and specialize in these things. She said it’s a wonderful thing to see people solving their problems on PC, mobile photos, and other devices; it’s a sense of accomplishment. Sarah likes to make friends in life and she’s a huge music fan.

batch file to copy files to another location?

Is it possible to create a batch file to copy a folder to another location everytime I login, or when the folder is updated?

It could be written in VB or Java as well if not an easy solution.

8 Answers 8

When you login: you can to create a copy_my_files.bat file into your All Programs > Startup folder with this content (its a plain text document):

Use xcopy c:\folder\*.* d:\another_folder\. /Y to overwrite the file without any prompt.

Everytime a folder changes: if you can to use C#, you can to create a program using FileSystemWatcher

Type the following lines into it (obviously replace the folders with your ones)

Save the file as backup.bat (not .txt)

Double click on the file to run it. It will backup the folder and all its contents files/subfolders.

Now if you want the batch file to be run everytime you login in Windows, you should place it in Windows Startup menu. You find it under: Start > All Program > Startup To place the batch file in there either drag it into the Startup menu or RIGH click on the Windows START button and select Explore, go in Programs > Startup, and copy the batch file into there.

To run the batch file everytime the folder is updated you need an application, it can not be done with just a batch file.

Windows batch script to copy and modify files containing redirect characters

We are trying to convert a bash shell script into a Windows batch script. We ship these scripts with our software product, and we cannot assume that the customer will have, or will be able to download, sed/awk/cygwin or any other non-standard tools. Therefore, the script must work with whatever tools come out-of-the-box with Windows. The minimum target platform is Windows XP SP2. This script is called from another batch script.

One part of the script needs to search through a file for a particular string and modify that string. In bash, this is easy. The approach we are taking in the Windows batch script is to walk through the file, line by line. If a line does not contain the target string, we echo it to a temp file as-is. If a line contains the target string, we echo a hardcoded string to the temp file.

The problem is that some lines of the input file contain the less-than and greater-than signs. If we put quotation marks around the lines, they are written intact to the temp file, but quoted.

If we unquote them using %

1, then CMD.EXE attempts to treat the as redirection symbols, and produces errors when the script encounters one of those lines, because the resulting command would be something like this:

Читайте также:  Kaspersky free windows server 2019

Here’s what we have right now. It produces the file contents with every line enclosed in quotation marks.

The question is, how can we echo the contents of a string to a file, unquoted, if the string contains redirect symbols? If that can’t be done, then is there another way to accomplish our original goal, which is to take as input a file that may or may not contain a certain target string, and produce as output a file that is identical to the original file except that if that target string existed, it is replaced by a new string?

Note: Please don’t suggest Cygwin, sed, awk, Perl, Python, Ruby, unx, or any other technology that does not ship with Windows XP out of the box. Those answers will be voted down.

copying all contents of folder to another folder using batch file?

I have a folder in C:\Folder1

I want to copy all the contents of Folder1 to another location, D:\Folder2

How do I do this using a batch file?

12 Answers 12

xcopy.exe is the solution here. It’s built into Windows.

If you have robocopy,

if you want remove the message that tells if the destination is a file or folder you just add a slash:

xcopy /s c:\Folder1 d:\Folder2\

I see a lot of answers suggesting the use of xcopy. But this is unnecessary. As the question clearly mentions that the author wants THE CONTENT IN THE FOLDER not the folder itself to be copied in this case we can -:

Thats all xcopy can be used for if any subdirectory exists in C:\Folder1

RoboCopy did not work for me, and there are some good solutions here, but none explained the XCopy switches and what they do. Also you need quotes in case your path has spaces in it.

xcopy /i /e «C:\temp\folder 1» «C:\temp\folder 2»

Here is the documentation from Microsoft:

On my PC, xcopy and robocopy need also the path to them, i.e. C:\Windows\System32\xcopy.exe

That’s why I use simply «copy»: copy /y . \Folder1\File.txt . \Folder2\

This is how it is done! Simple, right?

Here’s a solution with robocopy which copies the content of Folder1 into Folder2 going trough all subdirectories and automatically overwriting the files with the same name:

/COPYALL copies all file information
/E copies subdirectories including empty directories
/IS includes the same files
/IT includes modified files with the same name

Note: it can be necessary to run the command as administrator, because of the argument /COPYALL . If you can’t: just get rid of it.

FYI. if you use TortoiseSVN and you want to create a simple batch file to xcopy (or directory mirror) entire repositories into a «safe» location on a periodic basis, then this is the specific code that you might want to use. It copies over the hidden directories/files, maintains read-only attributes, and all subdirectories and best of all, doesn’t prompt for input. Just make sure that you assign folder1 (safe repo) and folder2 (usable repo) correctly.

And, that’s it folks!

Add to your scheduled tasks and never look back.

I have written a .bat file to copy and paste file to a temporary folder and make it zip and transfer into a smb mount point, Hope this would help,

Оцените статью