1

I've tried adding quotation marks around filepaths, and replacing quotation marks with 0x22. Also tried other variables and they all return the same kind of error. Tried one equal, two equals, all capitals... Everything looks right, but I don't understand why it's not working, would appreciate any help. Thanks.

set source=N:\Movies\
set target=M:\Movies\

forfiles /P "%source%" /C "cmd /c if @isdir==TRUE ( mklink /d 0x22%target%\@file\0x22 @path ) else ( mklink 0x22%target%\@file\0x22 @path )"

This is the error:

ERROR: Invalid argument/option – '@isdir==TRUE'.
davidtgq
  • 3,780
  • 10
  • 43
  • 80
  • [http://stackoverflow.com/questions/1039221/forfiles-batch-script-escaping-character](http://stackoverflow.com/questions/1039221/forfiles-batch-script-escaping-character) –  Jan 24 '16 at 14:46

2 Answers2

4

The selected answer doesn't work as the comments say. Remove the quotes around %source% and it will work (tested):

set source=N:\Movies\
set target=M:\Movies\

forfiles /P %source% /C "cmd /c if @isdir==TRUE echo @path"

If you test that with the quotes around %source%, you'll get that same error. Basically the quotes screw up your @path even if you're not using the variable and simply putting the path itself. Leave the quotes off.

Sum None
  • 2,164
  • 3
  • 27
  • 32
1

you need to treat the @isdir as a string

  @isdir   Returns "TRUE" if a file type is a directory,
           and "FALSE" for files.

So: @isdir=="TRUE"

Source: http://ss64.com/nt/forfiles.html

Shevek
  • 3,869
  • 5
  • 43
  • 63
  • That results in: ERROR: Invalid argument/option – '@isdir' – davidtgq Jun 21 '15 at 02:13
  • Sorry I prematurely clicked the answer button. That didn't work either, but in the examples they actually use it without quotation marks if isdir==FALSE I tried switching it around to FALSE and it still didn't work. – davidtgq Jun 21 '15 at 02:45
  • Well this worked, still don't know why the variables won't work the other way around: `N: cd movies forfiles /C "cmd /c if @isdir==TRUE mklink /d M:\Movies\@file\ @path" forfiles /C "cmd /c if @isdir==FALSE mklink M:\Movies\@fname @path"` It's still important that I figure it out the first way so I can automate this task. – davidtgq Jun 21 '15 at 03:16