0

I have a CMD Command and it only works after the third time of execution. I want to open a command which gives me a path after that I want to convert the path and in the end I want to show the input of the file.

Here is my command:

@echo off & for /f %A in ('getFilePath') do set string="C:%A" & set newstring=%string:/=\% & type %newstring% & @echo on
Marged
  • 10,577
  • 10
  • 57
  • 99
  • 1
    What is the `getFilePath` command? Would you consider reformatting this as a .bat script until it is working, then convert it into a one-liner? Please edit the original post. – lit Feb 03 '16 at 14:26

2 Answers2

0

Finally i found a solution i am sure it’s not the best way but it works for me.

@echo off & for /f %A in ('getFilePath') do ( set script=%A & call type C:%script:/=\\%) & @ECHO ON
0
@echo off & for /f %A in ('getFilePath') do set string="C:%A" & set newstring=%string:/=\% & type %newstring% & @echo on

would need delayed expansion (also your answer wouldn't work without delayed expansion), but astonishingly type "c:/path/file.ext" works (type c:/path/file.ext doesn't), so you can just do:

@echo off & @for /f %A in ('getFilePath') do @type "C:%A"  & @echo on

(assuming getFilePath gives you something like /path/file.ext)

Community
  • 1
  • 1
Stephan
  • 53,940
  • 10
  • 58
  • 91