- Windows copy command syntax and examples
- Copy the contents of a file to another file
- Copy file to another directory
- Copy files with white space in name
- Copy multiple files
- Use of environment variables
- Windows Machine File Copy task
- YAML snippet
- Arguments
- Open source
- I get a system error 53 when using this task. Why?
- Do I need an agent?
- I’m having problems. How can I troubleshoot them?
- I can’t select a default agent pool and I can’t queue my build or release. How do I fix this?
- My NuGet push task is failing with the following error: «Error: unable to get local issuer certificate». How can I fix this?
- I use TFS on-premises and I don’t see some of these features. Why not?
- Create installation media for Windows
- INF CopyFiles Directive
- Entries
- Remarks
- Examples
Windows copy command syntax and examples
Using copy command, we can copy files from one directory to another directory. This command is similar to the Linux cp command, but it does not match with the full functionality of cp. Windows copy command can be used to copy files only, we can’t copy directories.
The syntax and usecases of copy command are explained below with examples.
Copy the contents of a file to another file
Example: To copy a file from c:\data\file1.doc to D:\backup\file2.doc
If the destination file already exists you will be prompted for confirmation. To suppress this confirmation you can use /Y switch with copy command. This would be useful if you are executing copy command from a batch file.
If the destination file exists, the above command will overwrite the same without asking the user for confirmation.
Copy file to another directory
When we specify a directory path as the destination, the files will be copied with the same name. We can assign a different name by specifying the new name in the destination path. Example is shown below.
To copy the file 1.doc loated at c:\data\documents to the directory c:\data\newdocs
Copy files with white space in name
If the file name has white space within it, we can wrap up the name in double quotes.
Example: To copy file, my resume.doc to another folder
Copy multiple files
We can’t specify multiple file names in copy command. However, we can use wildcards to identify a group of files and then copy all of them in a single command.
For example, to copy all excel files from current folder to another folder F:\backup
To copy all files in current folder to another folder
Use of environment variables
We can use environment variables in the copy command to specify the path of the folders. Like USERPROFILE, SystemRoot, ProgramFiles, TEMP, WINDIR, APPDATA, HOMEPATH.
For example, to copy a file to a user’s documents folder
The above command copies the file to the My Documents folder of the current logged in user.
You may also want to read
Windows «copy» is funny. Type «copy 1 2» and the file «1» will be copied into a new file «2». Now separate them by a plus sign instead of a space (copy 1+2) and you’ll concatenate 1 and 2 and replace the old file «1» with the result of the concatenation!
Yes, we can concatenate two or more files using copy command. You need to separate the list of files using +. You can redirect the resultant data to a new file also.
The above command will not alter the file 1. It creates a new file 3 with the concatenated data of 1 & 2. If no file name is provided it stores the result in the first file.
My Win7 cannot find a copy command, and when i run xcopy, a window flashes and exits.
I have the same problem. If you solved it, could you please explain how?
If you can not find your copy.exe file, you can download it to your windows directory or C:\ Directory depending the setting on your OS you should also be able to copy and run it from system32 or system folder.
how can i combine 2 .exe files and be able to use both after concatenation
I want to copy 2 different files(.exe,.config) from source to destination server of windows.
can you please help me on this command.
Hello i have a problem with my cmd windows 7.when i try to copy a command. Like help > file.pdf. i mean in extension pdf because i have this problem only with .pdf extension but not with .txt.So whe i execute the command. No problem. Then when i go to open the file.pdf ftom user destination the file.pdf doesn’t open say that is corrupted.please do help me .thanks
i have a file contain many lines as sources and another file has the same numbre of lines as destinations. i want to copy first line as source( c:/test/*.txt) to first line in destination ( d:/test2/), secend line ( c:/test/*.pdf) to second line in destination ( E:/test3/)……
Can I use the DOS/Windows “COPY” command in a BAT file to copy a file or a short string of text to computer memory and then paste (Ctrl +V) that string or file into a document?
Windows Machine File Copy task
Azure Pipelines | Azure DevOps Server 2020 | Azure DevOps Server 2019 | TFS 2018 — TFS 2015
Use this task to copy application files and other artifacts such as PowerShell scripts and PowerShell-DSC modules that are required to install the application on Windows Machines. It uses RoboCopy, the command-line utility built for fast copying of data.
In Microsoft Team Foundation Server (TFS) 2018 and previous versions, build and release pipelines are called definitions, runs are called builds, service connections are called service endpoints, stages are called environments, and jobs are called phases.
YAML snippet
Arguments
Argument | Description |
---|---|
Source | The path to the files to copy. Can be a local physical path such as c:\files or a UNC path such as \\myserver\fileshare\files . You can use pre-defined system variables such as $(Build.Repository.LocalPath) (the working folder on the agent computer), which makes it easy to specify the location of the build artifacts on the computer that hosts the automation agent. |
Machines | A comma-separated list of machine FQDNs or IP addresses, optionally including the port number. Can be: — The name of an Azure Resource Group. — A comma-delimited list of machine names. Example: dbserver.fabrikam.com, dbserver_int.fabrikam.com:5986,192.168.34:5986 — An output variable from a previous task. |
Admin Login | The username of either a domain or a local administrative account on the target host(s). — Formats such as domain\username, username, and machine-name\username are supported. — UPN formats such as username@domain.com and built-in system accounts such as NT Authority\System are not supported. |
Password | The password for the administrative account specified above. Consider using a secret variable global to the build or release pipeline to hide the password. Example: $(passwordVariable) |
Destination Folder | The folder on the Windows machine(s) to which the files will be copied. Example: C:\FabrikamFibre\Web |
Advanced — Clean Target | Set this option to delete all the files in the destination folder before copying the new files to it. |
Advanced — Copy Files in Parallel | Set this option to copy files to all the target machines in parallel, which can speed up the copying process. |
Advanced — Additional Arguments | Arguments to pass to the RoboCopy process. Example: /min:33553332 /l |
Select Machines By | Depending on how you want to specify the machines in the group when using the Filter Criteria parameter, choose Machine Names or Tags. |
Filter Criteria | Optional. A list of machine names or tag names that identifies the machines that the task will target. The filter criteria can be: — The name of an Azure Resource Group. — An output variable from a previous task. — A comma-delimited list of tag names or machine names. Format when using machine names is a comma-separated list of the machine FQDNs or IP addresses. Specify tag names for a filter as |
Control options | See Control options |
Open source
This task is open source on GitHub. Feedback and contributions are welcome.
I get a system error 53 when using this task. Why?
Typically this occurs when the specified path cannot be located. This may be due to a firewall blocking the necessary ports for file and printer sharing, or an invalid path specification. For more details, see Error 53 on TechNet.
Do I need an agent?
You need at least one agent to run your build or release.
I’m having problems. How can I troubleshoot them?
I can’t select a default agent pool and I can’t queue my build or release. How do I fix this?
My NuGet push task is failing with the following error: «Error: unable to get local issuer certificate». How can I fix this?
This can be fixed by adding a trusted root certificate. You can either add the NODE_EXTRA_CA_CERTS=file environment variable to your build agent, or you can add the NODE.EXTRA.CA.CERTS=file task variable in your pipeline. See Environment variables for more details.
I use TFS on-premises and I don’t see some of these features. Why not?
Some of these features are available only on Azure Pipelines and not yet available on-premises. Some features are available on-premises if you have upgraded to the latest version of TFS.
Create installation media for Windows
You can use installation media (a USB flash drive or DVD) to install a new copy of Windows, perform a clean installation, or reinstall Windows 10.
To create installation media, go to the software download website, where you’ll find step-by-step instructions. On that website, you can select a version of Windows and create your own installation media using either a USB flash drive or a DVD. To go directly to one of the versions, select one of these links:
Windows 10 (Then select Download tool now.)
Important: Back up your files before you install or reinstall Windows on your PC. Learn how for Windows 10 or for Windows 7 and Windows 8.1.
To create the installation media, here’s what you’ll need:
A PC with a reliable internet connection. The download time will vary, depending on your internet connection.
A USB flash drive or DVD. A blank USB flash drive with at least 8 GB of space, or a blank DVD (and DVD burner). We recommend using a blank USB or blank DVD because any content on it will be deleted. When burning a DVD from an ISO file, if you’re told the disc image file is too large, you’ll need to use dual layer (DL) DVD media.
A product key. Your 25-character product key (not required for digital licenses). For help finding it, go to Find your Windows product key.
After you’ve created the installation media, you can reset or reinstall Windows. To learn more, go to Recovery options in Windows 10.
INF CopyFiles Directive
A CopyFiles directive can do either of the following:
- Cause a single file to be copied from the source media to the default destination directory.
- Reference one or more INF-writer-defined sections in the INF that each specifies a list of files to be copied from the source media to the destination.
A CopyFiles directive can be specified within any of the sections shown in the formal syntax statement. This directive can also be specified within any of the following INF sections:
Each named section referenced by a CopyFiles directive has one or more entries of the following form:
An INF-writer-defined file-list-section can have any number of entries, each on a separate line.
Each file-list-section can have an optional, associated file-list-section.security section of the following form:
Entries
destination-file-name
Specifies the name of the destination file. If no source-file-name is given, this specification is also the name of the source file.
source-file-name
Specifies the name of the source file. If the source and destination file names for the file copy operation are the same, source-file-name can be omitted.
unused
This entry is no longer supported in Windows 2000 and later versions of Windows.
flag
These optional flags, expressed in hexadecimal notation or as a decimal value in a section entry, can be used to control how (or whether) a particular source file is copied to the destination. One or more (ORed) values for the following system-defined flags can be specified. However, some of these flags are mutually exclusive:
0x00000001 (COPYFLG_WARN_IF_SKIP)
Send a warning if the user chooses not to copy a file. This flag and the next are mutually exclusive, and both are irrelevant to INF files that are digitally signed.
0x00000002 (COPYFLG_NOSKIP)
Do not allow the user to skip copying a file. This flag is implied if the driver package is signed.
0x00000004 (COPYFLG_NOVERSIONCHECK)
Ignore file versions and write over existing files in the destination directory. This flag and the next two are mutually exclusive. This flag is irrelevant to digitally signed INF files.
0x00000008 (COPYFLG_FORCE_FILE_IN_USE)
Force file-in-use behavior: do not copy over an existing file of the same name if it is currently open. Instead, copy the given source file with a temporary name so that it can be renamed and used when the next restart occurs.
0x00000010 (COPYFLG_NO_OVERWRITE)
Do not replace an existing file in the destination directory with a source file of the same name. This flag cannot be combined with any other flags.
0x00000020 (COPYFLG_NO_VERSION_DIALOG)
Do not write over a file in the destination directory with the source file if the existing file is newer than the source file.
The newer check is done using the file version, as extracted from the VS_VERSIONINFO file version resource. For more info, see Version Information. If the target file is not an executable or resource image, or the file does not contain file version information, then device install assumes that the target file is older.
0x00000040 (COPYFLG_OVERWRITE_OLDER_ONLY)
Copy the source file to the destination directory only if the file on the destination is superseded by a newer version. This flag is irrelevant to digitally signed INF files. The version check uses the same procedure as that described above in COPYFLG_NO_VERSION_DIALOG.
0x00000400 (COPYFLG_REPLACEONLY)
Copy the source file to the destination directory only if the file is already present in the destination directory.
0x00000800 (COPYFLG_NODECOMP)
(Windows 7 and later) Copy the source file to the destination directory without decompressing the source file if it is compressed.
0x00001000 (COPYFLG_REPLACE_BOOT_FILE)
This file is required by the system loader. The system will prompt the user to restart the system.
0x00002000 (COPYFLG_NOPRUNE)
Do not delete this operation as a result of optimization.
For example, Windows might determine that the file copy operation is not necessary because the file already exists. However, the writer of the INF knows that the operation is required and directs Windows to override its optimization and perform the file operation.
This flag can be used to ensure that files are copied if they are also specified in an INF DelFiles directive or an INF RenFiles directive.
0x00004000 (COPYFLG_IN_USE_RENAME)
If the source file cannot be copied because the destination file is being used, rename the destination file, then copy the source file to the destination file, and delete the renamed destination file. If the destination file cannot be renamed, complete the copy operation during the next system restart. If the renamed destination file cannot be deleted, delete the renamed destination file during the next system restart.
security-descriptor-string
Specifies a security descriptor, to be applied to all files copied by the named file-list-section. The security-descriptor-string is a string with tokens to indicate the DACL (D:) security component.
For information about security descriptor strings, see Security Descriptor Definition Language (Windows). For information about the format of security descriptor strings, see Security Descriptor Definition Language (Windows).
If an file-list-section.security section is not specified, files inherit the security characteristics of the directory into which the files are copied.
If an file-list-section.security section is specified, the following ACE’s must be included so that installations and upgrades of devices and system service packs can occur:
- (A;;GA;;;SY) в€’ Grants all access to the local system.
- (A;;GA;;;BA) в€’ Grants all access to built-in administrators.
Do not specify ACE strings that grant write access to nonprivileged users.
For more information about how to specify security descriptors, see Creating Secure Device Installations.
Remarks
Windows only copies a driver package to its destination location as part of a driver installation if the file has an INF CopyFiles directive. When it copies files, the operating system automatically generates temporary file names, when necessary, and renames the copied source files the next time that the operating system is started.
The INF file writer must also supply path specifications for files that are copied from source media by using the INF SourceDisksNames section and the INF SourceDisksFiles section to explicitly specify the path of each source file relative to the INF file in the source media.
The destination of copy operations is controlled by the INF DestinationDirs section. This section controls the destination for all file-copy operations, as follows:
- If a named section referenced by a CopyFiles directive has a corresponding entry in the DestinationDirs section of the same INF, that entry explicitly specifies the target destination directory into which all files that are listed in the named section are copied. If the named section is not listed in the DestinationDirs section, Windows uses the DefaultDestDir entry in the DestinationDirs section of the INF file.
- If a CopyFiles directive uses the @filename syntax, Windows uses the DefaultDestDir entry in the DestinationDirs section of the INF file.
The following points apply to the INF CopyFiles directive:
- Every file-list-section name must be unique to the INF file, but it can be referenced by CopyFiles, DelFiles, or RenFiles directives elsewhere in the same INF file. The section name must follow the general rules that are described in General Syntax Rules for INF Files.
- File names that are specified in either the @filename or file-list-section entries must be the exact name of a file on the source media. You cannot use a %strkey% token to specify the file name. For more information about %strkey% tokens, see INF Strings Section.
- The CopyFiles directive does not support decorating a file-list-section name with a system-defined platform extension (.nt, .ntx86, .ntia64, or .ntamd64).
- Do not use CopyFiles directives to copy INF files. For more information, see Copying INF Files.
Starting with Windows Vista, the following points also apply to the INF CopyFiles directive:
- When the DIFx tools preinstall a driver package in the driver store, they only copy a file from the driver package source to the driver store if the file has a corresponding INF CopyFiles directive.
- As part of a Windows upgrade, Windows only copies a driver package file to the driver store as part of a driver migration if the file has an INF CopyFiles directive.
Examples
This example shows how the SourceDisksNames, SourceDisksFiles, and DestinationDirs sections specify the paths for copy-file (and delete-file) operations that occur in processing a simple device-driver INF. (The same INF was also used previously as examples of Version, SourceDisksNames, and SourceDisksFiles sections.)
This example shows how a CopyFiles directive can be used in a DDInstall.CoInstallers section of an INF for a device driver that provides two device-specific co-installers to supplement the INF processing of the system device-type-specific class installer.
As the preceding example suggests, the names of new device-specific co-installers can be constructed from the name of the provider (shown here as Xx) and the intended use for each such co-installer DLL (shown here as PreInst and PostInst).
For additional examples of how to use the INF CopyFiles directive, see the INF files for the device driver samples that are included in the src directory of the Windows Driver Kit (WDK).