Jump to content
Sign in to follow this  
Willow

Ipconfig output to text file with space in file path

Recommended Posts

Willow

I am struggling to output an "ipconfig /all" to a text file where the file path has a space in it. I know that it is probably just the proper placement of quotes for the path but I cannot get it...

The first line of the sample code creates the folder. The second line then runs the ipconfig /all and in theory, saves it to the newly created folder as a text file. Therein lies the problem. I cannot get the text file to be created in the folder due to the space between "pc inventory" no matter what quote placement I use(d).

DirCreate("c:\pc inventory\"& @MON & "\pc1")


Run("cmd /c ipconfig /all" > "c:\pc inventory\"& @MON & "\pc1\ip.txt")

Thanks in advance.

Share this post


Link to post
Share on other sites
DW1

You were right, just placement of quotes. You want to double quote the parameter with a space in it. If we need to pass double quotes (there are many ways to do this) I prefer to start with a single quote.

DirCreate("c:pc inventory"& @MON & "pc1")
Run('cmd /c ipconfig /all > "c:pc inventory'& @MON & 'pc1ip"')

EDIT: Explanation

To test these things in the future, it's easy enough to place the parameter in a message box.

If you put your string in a message box: MsgBox(0,'Test', "cmd /c ipconfig /all" > "c:pc inventory"& @MON & "pc1ip.txt")

you will find that it returns "True" because the way you placed the quotes is saying "cmd /c ipconfig /all" MORE THAN "c:pc inventory"& @MON & "pc1ip.txt".

If you were to fix the string to put the ">" inside the quotes, you would have MsgBox(0,'Test', "cmd /c ipconfig /all > c:pc inventory"& @MON & "pc1ip.txt") which returns: cmd /c ipconfig /all > c:pc inventory03pc1ip.txt

notice the lack of quotes.

What we wanted to see was cmd /c ipconfig /all > "c:pc inventory03pc1ip.txt"

So I picked one of many ways to add the double quotes in the right spot; MsgBox(0,'Test', 'cmd /c ipconfig /all > "c:pc inventory'& @MON & 'pc1ip"')

which returns: cmd /c ipconfig /all > "c:pc inventory03pc1ip"

Edited by danwilli

Share this post


Link to post
Share on other sites
Willow

Thanks Danwilli for the thorough explanation. Getting quotes in the right place and within syntax is an area I always struggle with...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×