-1

i am trying to change windows file association via ruby. Assoc part works but ftype does not work why it does not work?

    pth = Dir.pwd
    pth << "/pfReader.exe"

    pth.gsub "/","\\"


    system("assoc .pf=pfReader")
    puts("assoc command is done \n")
    system("ftype pfReader = '#{pth}' '%1'")
    puts("ftype command is done \n")
dub
  • 21
  • 1
  • 9
  • 1
    Can you explain what "does not work" actually means? – engineersmnky May 08 '18 at 20:32
  • @engineersmnky when i run this file it doesen't set the base program for the .pf file to be pfReader ("Think like when you are running python file double click on it it runs python.exe same thing") – dub May 08 '18 at 20:38

1 Answers1

1

A good hint to debug problems like these is to replace system with puts. If you do that, you will realize the problem is on this line:

pth.gsub "/","\\"

While you probably wanted this:

pth.gsub! "/","\\"

Also I'm not sure the Windows cmd.exe likes single quotes, so you probably need to fix your ftype call also to use the proper double quotes:

system("ftype pfReader=\"#{pth}\" \"%1\"")
Casper
  • 33,403
  • 4
  • 84
  • 79
  • Thanks can i ask how can i use " instead of ' i think about that too but if i do system(" ftype"label"="Code" ") string would not be ftype"label"="Code" instead it will be "ftype","="," " (Also would gave an error but you get my point) --edit-- with a google search i found what i was looking for thanks – dub May 08 '18 at 21:28