Jump to content

C:\ or C: @WorkingDir


Recommended Posts

Hello All,

I made a script today and find a "funny" thing:

FileChangeDir("C:\")
ConsoleWrite(@WorkingDir & @CRLF )
FileChangeDir("C:\windows")
ConsoleWrite(@WorkingDir & @CRLF )
;
$file = "myfile.txt"
FileChangeDir("C:\")
ConsoleWrite(@WorkingDir & $file & @CRLF )
FileChangeDir("C:\windows")
ConsoleWrite(@WorkingDir & $file & @CRLF )

result:

C:\
C:\windows
C:\myfile.txt
C:\windowsmyfile.txt

So,... I have a kind of problem when I want to put files in variables and the files are both on the root and on subdirectories...

The "@WorkingDir" should return "C:" on the root !

What do you think ? and

How can we go around this problem ?

Edited by cramaboule
Link to comment
Share on other sites

I fail to see your problem.

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

Per Help File: Result of @WorkingDir does not contain a trailing backslash. You need to add your own.

Thanks I know that,... so,... why on the root like "C:" I HAVE a trailing backslash ???? ("C:\")

Link to comment
Share on other sites

Ahh.. I see.. apparently when the workingdir is the root of a given drive it DOES include the trailing \

Func _MyWorkingDir()
    If StringLen(@WorkingDir) = 3 Then
        Return StringTrimRight(@WorkingDir,1)
    Else
        Return @WorkingDir
    EndIf
EndFunc

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

  • Developers

Thanks I know that,... so,... why on the root like "C:" I HAVE a trailing backslash ???? ("C:\")

Because that is the only way to represent the root of a drive .... ever seen how the CMD does it?

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

Just test for the Right character and add the extra "\" when needed.

Jos

okay thanks

Would it not be easier to return only C: with @WorkingDir. Then you always add a "\" ?

just asking !!!

Link to comment
Share on other sites

Because that is the only way to represent the root of a drive .... ever seen how the CMD does it?

just missed you answer !!!

heu.... yeeee

No I've never seen the cmd :D:o:D

Link to comment
Share on other sites

It's an interesting feature, when you try an operation like "C:runprogram.exe" it will actually look at the working folder on the C: drive. But when you add the '\', then it looks at the root of the drive. So if the working folder is 'C:\Windows', you can use "C:explorer.exe" to run explorer.exe from that subfolder. 'C:\explorer.exe' would fail obviously, as it's looking for it in the wrong place.

Link to comment
Share on other sites

okay thanks

Would it not be easier to return only C: with @WorkingDir. Then you always add a "\" ?

just asking !!!

You can still always add '\' to the string, windows doesn't make a difference between "C:\" and "C:\\", or "C:\\\\\\\" for that matter.

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

Actually I wanted to "ShellExecute()" some programs on a USB key (with my AUtoIt on the USB key !) so as the USB key may change letter from computer to computer, I used @WorkingDir. But, as soon as I created a folder (on the USB key) nothing was working any more !!!!

Amazing!!! this works !!!: :D

ShellExecute("G:\\folder\\\myprog.txt")

Edited by cramaboule
Link to comment
Share on other sites

ConsoleWrite(StringReplace(@WorkingDir & $File, "\\", "\"))

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

I'm going to start shooting people that ask this.

C: is NOT A PATH. It's a drive letter. It is NOT A PATH. Got it? Not a path. It's invalid. Not. A. Path. Drive. Letter.

Seriously, a drive letter is not a valid path. We must add a trailing slash, otherwise we return INVALID data.

Why are people so resistant to doing basic sanity checking they should be doing anyway?

Link to comment
Share on other sites

I'm going to start shooting people that ask this.

C: is NOT A PATH. It's a drive letter. It is NOT A PATH. Got it? Not a path. It's invalid. Not. A. Path. Drive. Letter.

Seriously, a drive letter is not a valid path. We must add a trailing slash, otherwise we return INVALID data.

Why are people so resistant to doing basic sanity checking they should be doing anyway?

BANG ! I'm dead !!! :o

It is, I presume, because I am too puristic !!!! :D

Link to comment
Share on other sites

C: is NOT A PATH. It's a drive letter. It is NOT A PATH. Got it? Not a path. It's invalid. Not. A. Path. Drive. Letter.

Seriously, a drive letter is not a valid path. We must add a trailing slash, otherwise we return INVALID data.

Why are people so resistant to doing basic sanity checking they should be doing anyway?

Actually, it's as valid a path as '.' or '..' is, as far as Windows is concerned. (a type of 'pointer' you could say). Otherwise, things like this wouldn't work:

FileChangeDir ("C:\Windows")

Run("C:explorer.exe "&@SystemDir)

Link to comment
Share on other sites

Actually, it's as valid a path as '.' or '..' is, as far as Windows is concerned. (a type of 'pointer' you could say). Otherwise, things like this wouldn't work:

FileChangeDir ("C:\Windows")

Run("C:explorer.exe "&@SystemDir)

I always forget that. So a better phrasing is that C: is not the same as C:\. C: actually means "Working directory for drive C:" which is even more unexpected than the trailing slash. The point is, it does not make sense for us to return just "C:".
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...