Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing file paths to a batch file
    text
    copied!<p>I'm calling a .bat file to XCOPY a folder. Is there anyway to pass the file name and the destination into the batch file?</p> <p>My .bat file </p> <pre><code>XCOPY %1 %2 pause </code></pre> <p>The code I'm using to call the .bat is this:</p> <pre><code>process.Start(@"C:\Documents and Settings\cmolloy\My Documents\Test\XCOPY.bat"); </code></pre> <p>I've tried this code</p> <pre><code>process.Start(@"C:\Documents and Settings\cmolloy\My Documents\Test\XCOPY.bat" , copyfrom copyto); </code></pre> <p>As i've used that before for shutting down my comp, but it doesn't work with this.</p> <p>Thanks</p> <p><strong>Update</strong></p> <pre><code>process.StartInfo.FileName = @"C:\Documents and Settings\cmolloy\My Documents\Test\XCOPY.bat"; process.StartInfo.Arguments = copyFrom.ToString(); process.StartInfo.Arguments = copyTo.ToString(); process.Start(); </code></pre> <p>That is the code I'm using but It doesn't work. I'm getting this from the XCOPY screen: <img src="https://i.stack.imgur.com/7fcV6.png" alt="enter image description here"></p> <p>So it doesn't look like its taking the full file paths. copyto and copyfrom are variables that contain the paths.</p> <p><strong>UPDATE</strong></p> <p>Using azhrei's code:</p> <pre><code>String batch = @"C:\Documents and Settings\cmolloy\My Documents\Test\XCOPY.bat"; String src = @"C:\Tricky File Path\Is Here\test1.txt"; String dst = @"C:\And\Goes Here\test2.txt"; String batchCmd = String.Format("\"{0}\" \"{1}\" \"{2}\"", batch, src, dst); process.StartInfo.FileName = "cmd.exe"; process.StartInfo.Arguments = String.Format("/k \"echo {0}\"", batchCmd); process.Start(); </code></pre> <p>I'm getting this output: <img src="https://i.stack.imgur.com/h7Enf.jpg" alt="enter image description here"></p> <p>Which isn't actually copying the file.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload