Ci-dessous, les différences entre deux révisions de la page.
| info:copy [2022/10/13 12:57] – créée frog | info:copy [2022/10/13 12:59] (Version actuelle) – frog | ||
|---|---|---|---|
| Ligne 3: | Ligne 3: | ||
| - | Copy Command | + | ==== Copy Command |
| On Windows, we can use the copy command to copy one or more files from one location to another: | On Windows, we can use the copy command to copy one or more files from one location to another: | ||
| Ligne 11: | Ligne 12: | ||
| Use the /y switch to overwrite duplicate files without confirmation: | Use the /y switch to overwrite duplicate files without confirmation: | ||
| - | copy /y C: | + | < |
| We can also save a file to a different name. For example, the following command saves file1.txt as file2.txt in the same directory: | We can also save a file to a different name. For example, the following command saves file1.txt as file2.txt in the same directory: | ||
| - | copy file1.txt file2.txt | + | < |
| You can also use wildcards to copy multiple files: | You can also use wildcards to copy multiple files: | ||
| - | copy /y C:\data\* C:\backup | + | < |
| - | copy /y C: | + | copy /y C: |
| The first command copies all files in the C:\data\ directory to C:\backup. The second command copies all files with a .doc extension to the C:\backup. | The first command copies all files in the C:\data\ directory to C:\backup. The second command copies all files with a .doc extension to the C:\backup. | ||
| Ligne 24: | Ligne 25: | ||
| We can also combine several files into one: | We can also combine several files into one: | ||
| - | copy file1+file2 file3 | + | < |
| - | copy error* C: | + | copy error* C: |
| In the first line, file1 and file2 are combined to make one file named file3. In the second line, all files whose names start with " | In the first line, file1 and file2 are combined to make one file named file3. In the second line, all files whose names start with " | ||
| You can get a list of all available options with the copy /? command. | You can get a list of all available options with the copy /? command. | ||
| - | Xcopy Command | + | ==== Xcopy Command |
| The xcopy command offers more features. For example, with xcopy, we can copy directories and subdirectories, | The xcopy command offers more features. For example, with xcopy, we can copy directories and subdirectories, | ||
| Ligne 48: | Ligne 50: | ||
| Copy sales.doc from the current directory to C:\backup: | Copy sales.doc from the current directory to C:\backup: | ||
| - | xcopy sales.doc C:\backup | + | < |
| Copy C: | Copy C: | ||
| - | xcopy /s /e /h /i /y C: | + | < |
| - | xcopy command | + | xcopy command</ |
| In the following example (without /I switch), the contents of the folder are copied but not the folder itself: | In the following example (without /I switch), the contents of the folder are copied but not the folder itself: | ||
| - | xcopy /s /e /h /y C: | + | < |
| Copy the directory structure of C:\OneDrive to the backup directory: | Copy the directory structure of C:\OneDrive to the backup directory: | ||
| - | xcopy /s /e /t /y C:\OneDrive C:\backup\ | + | < |
| You can use wildcard characters to match patterns. The following command copies all files with a .jpg extension: | You can use wildcard characters to match patterns. The following command copies all files with a .jpg extension: | ||
| - | xcopy /s /h /y C: | + | < |
| Using for loop to copy multiple files: | Using for loop to copy multiple files: | ||
| - | for %i in (sales.doc, products.doc) do xcopy /y %i C:\backup | + | < |
| Excluding files with xcopy | Excluding files with xcopy | ||
| With the /exclude, we can provide a text file that contains items we want to exclude. | With the /exclude, we can provide a text file that contains items we want to exclude. | ||
| - | xcopy /s /e /h /y / | + | < |
| The files-to-exclude.txt may look like the following: | The files-to-exclude.txt may look like the following: | ||