cURL / Mailing Lists / curl-users / Single Mail


RE: How to download files to a specific directory?

From: Roth, Kevin P. <>
Date: Thu, 8 Jul 2004 08:12:14 -0400

It'll work just fine, and here's why. When you run it manually (from a command prompt), your "CWD" (current working directory) was the same folder as the batch file. But, if you had changed to a different directory first (e.g. C:\Temp\) and then ran the batch script using a fully-qualified path to the script (e.g. d:\downloads\a.bat), your CWD would have been C:\Temp\ (even though the script was located elsewhere). Most command-line tools (including of course curl) default to doing "things" in the CWD.

Your scheduling package obviously has a different CWD at the point in time that your script is started, which causes those files to spit out in the scheduler's directory.

Here's a very generic command that you can place at the top of ANY windows batch script (works on Windows2000 and above), that will CD to the folder your batch script is in, without having to hard-code the directory name:

  CD /D %~dp0

To help translate this, you're obviously aware that %1 is how a batch script reads the first command line parameter. Well, %0 is actually the path to the batch script itself (and is set automagically). Now add in the "~dp", which pulls out the Drive-Letter (d) and Path (p) portions of the fully-qualified path represented by %0. (By the way, the other two usable letters are n [file Name] and x [file Extension], and the four letters can be used in any combination after the ~).

Hope that helps!

- Kevin

-----Original Message-----
From: Glenn
Sent: Thu 7/8/04 7:19 AM
Tim Liljendahl <hitech <at>> writes:
> What about putting a 'cd directory' as the first thing in the .bat file?

Good thinking Tim!

I will try that, it sounds so simple so it will probably solve the problem. As
always I'll have to wait until it can be tested but I will post back if it
Received on 2004-07-08