Jump to content
Karan

FileChangeDir does not work

Recommended Posts

Karan

I am trying to use the CmdLine argument from a cmd window to run the compiled exe. The argument is the file full path. (re-creating the scenario of drag and drop). The compiled script was tested in two ways. One, direct drag and drop of file onto the exe icon. and the other from a cmd window. In the compiled exe, I change the working directory using FileChangeDIr($CmdLine[1]). This works perfectly fine when I drag and drop the file onto the exe. But I call the same exe from a cmd window, the FileChangeDir does not change the working directory but maintains it to be the default working directory when cmd was opened with. Is there a way to change the working directory in autoit so that the @‌WorkingDir changes even when I use cmd to start the program?

Share this post


Link to post
Share on other sites
Karan

No, I open a cmd window and enter the path of the executable with an argument. The argument being the full path including the filename.. The executable has the FileChanegDir() function called in and it retains the CMD's working dir name.

Share this post


Link to post
Share on other sites
Karan

Sorry if I didn't explain it right.

I open a Command window and execute my script with an argument as:

cmd ->

C:\abc\> "C:\folder\my.exe" "c:\xyz\input.file"

In the executable "my.exe":

FileChangeDir($CmdLine[1])
MsgBox(0,"",@WorkingDir)

The messagebox instead of displaying C:\xyz, it displays C:\abc when I open the cmd and execute. Whereas when I drag and drop the input.file on to the icon of my.exe, the messagebox reads C:\xyz

 

Share this post


Link to post
Share on other sites
Karan

understood. But how does drag and drop work when the input file is dragged on the executable? The argument it gets is still the same .. .

Share this post


Link to post
Share on other sites
Jos

I assume that the initial workdir is set to the directory of the file being dragged-and-dropped and not the script dir.

Try this one to check that:

MsgBox(0,"",@WorkingDir)
FileChangeDir($CmdLine[1])
MsgBox(0,"",@WorkingDir)

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
argumentum
$varDrag_Drop_Toss_howEver = "c:\xyz\input.file"
If StringInStr(FileGetAttrib($varDrag_Drop_Toss_howEver), "D") Then ; is a folder
    FileChangeDir($varDrag_Drop_Toss_howEver)
Else ; is NOT a folder , therefore we need to remove the file name from the full path to FileChangeDir
    FileChangeDir(StringLeft($varDrag_Drop_Toss_howEver, StringInStr($varDrag_Drop_Toss_howEver, '\', 0, -1) - 1))
EndIf

 

Edited by argumentum
fix the example :/

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

×