0

I have a piece of code i am trying to execute in a batch file it works fine when i run in in the command line but when i save it as a .bat file it fails with some weird symbols at the start of the line. This i think is related to the fact that the file type is UTF-8. I changed the encoding using notepad++ to ansi following the steps here from the thread Weird characters (´╗┐) at the start of a batch file

I tried to run the batch script now with the ANSI file format but it seems to ignore the PAUSE command so im unable to run the script or to trouble shoot it

Can anyone help

Script is

for /r "K:\Folder_A" %f in (*) do @xcopy /Y/D "%f" "C:\Folder_C"

John Smith
  • 167
  • 1
  • 8
  • 1
    Based on what you've provided, it might not be due to the encoding. Inside a batch file you need to use double `%%` instead of a single `%` when referencing variables. See [What does the percent sign (% and %%) in a batch file argument mean?](http://superuser.com/questions/670992/what-does-the-percent-sign-and-in-a-batch-file-argument-mean)... – Ƭᴇcʜιᴇ007 Jun 03 '16 at 14:48
  • ...and an example of the same problem, from the other way around: [FOR/DO command gives “Was unexpected at this time” when run from command prompt](http://superuser.com/questions/894475/for-do-command-gives-was-unexpected-at-this-time-when-run-from-command-prompt) – Ƭᴇcʜιᴇ007 Jun 03 '16 at 14:50
  • yes :)...thats the answer. Would you please add it as an answer and il tick it as correct – John Smith Jun 03 '16 at 14:51

1 Answers1

2

Unlike when you run a For loop command at the command prompt, when referencing the variables within a batch file, you need to double up the percent signs (ie: %%f).

Perhaps check out this other SU question for more info: What does the percent sign (% and %%) in a batch file argument mean?

Ƭᴇcʜιᴇ007
  • 111,883
  • 19
  • 201
  • 268