0

This is not programming question and is my first time asking a question, so I'm sorry if this is the wrong forum.

I am trying to copy files using a simple .cmd file. Some of the files are receiving the error:

The system cannot find the file specified.

I have determined that the issue revolves around the use of the percent sign in the name of the file. I cannot rename the files in question as they are linked with database entries.

Here is an example of the syntax being used to copy the file and the resultant entry in the log file.

The name of the cmd file is Copy_Docs_v2.cmd. Here is the command:

Copy "\\server\DATA\APP\TJSH1\9w%01!.DOC" "\\server\APP\Docs\filename.DOC" 

What appears in the log file is:

Copy "\\server\DATA\APP\TJSH1\9wCopy_Docs_v2.cmd1!.DOC" "\\server\APP\Docs\filename.DOC" 

The system cannot find the file specified.

The log file entries vary slightly depending on whether the filename contains a %2 or multiple percent signs in the name but they all receive the same error message.

So the question is how do you copy a file with a percent sign in the filename or is there a way to get the Windows command prompt to ignore percent signs in a command?

Compo
  • 36,585
  • 5
  • 27
  • 39
StLHarps
  • 13
  • 3
  • Perhaps this will help you: https://stackoverflow.com/questions/1907057/ignore-percent-sign-in-batch-file there are answers for using a batch file and the command prompt – Jacob H Sep 07 '17 at 19:45
  • `%` is used for variables / arguments. You should double it (`%%`) to use as a percent sign... – Usagi Miyamoto Sep 07 '17 at 19:47
  • Questions about general usage should be asked on SuperUser, linked at the bottom of this page. – Rob Sep 07 '17 at 20:18
  • Jacob H: Thanks for the response. I saw that answer, however, the answers did not clearly answer the question and in the question itself the users stated: "I'm not able to alter the file generated to escape this, such as by doubling percent signs (%%), escaping with / or ^ (caret), etc". Since many of the answers said use the caret to escape and others said you can't use the caret to escape, I was left scratching my head. – StLHarps Sep 07 '17 at 20:51

1 Answers1

1

You have to escape the '%' sign by adding another % which results in

Copy "\server\DATA\APP\TJSH1\9w%%01!.DOC" "\server\APP\Docs\filename.DOC"

Many characters such as \ = ( ) do not need to be escaped when they are used within a "quoted string" typically these are charcters you might find in a filename/path. The percent character is one exception to this rule, even though under NTFS % is a valid filename character.

Molitoris
  • 935
  • 1
  • 9
  • 31
  • Thank you that worked. I did a Replace on the cmd file Find % Replace with %% and the results of the log file show: Copy "\\server\DATA\APP\TSEH1\%4w02!.DOC" "\\server\App\Docs\filename.doc" 1 file(s) copied. – StLHarps Sep 07 '17 at 20:34