It does not really matter which character is used in the string assigned to environment variable FileCount, the length of the string matters which must be at least one character. xx means copying two files and xxxx would be for copying four files. The number of files to copy is determined by the number of x characters of the string assigned to environment variable FileCount. Please read this answer for details about the commands SETLOCAL and ENDLOCAL and what happens in background on using these two commands. The batch file first sets up a local environment with enabled command extensions as needed here and with delayed environment variable expansion disabled to be able to copy also files of which full qualified file name (drive path name extension) contain one or more exclamation marks. If not defined FileCount goto FileCopyDone %SystemRoot%\System32\xcopy.exe "%SourcePath%%%I" "%TargetPath%" /C /I /Q /H /R /Y >nul If not "%SourcePath:~-1%" = "\" set "SourcePath=%SourcePath%\" Setlocal EnableExtensions DisableDelayedExpansion This batch file can be used for the task to copy just the two newest files in specified source directory to the specified target directory independent on which directory is the current directory on execution of the batch file.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |