Jump to content

FileChangeDir does not work


Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • Developers

Call me slow but I still don't understand. :)

Isn't FileChanegDir() changing it for subsequent commands performs in your script?

Jos

 

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

  • Developers

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 etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

$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 :/

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...