Jump to content
Sign in to follow this  
cramaboule

C:\ or C: @WorkingDir

Recommended Posts

cramaboule

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

Share this post


Link to post
Share on other sites
SpookMeister

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]

Share this post


Link to post
Share on other sites
MrMitchell

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

Share this post


Link to post
Share on other sites
cramaboule

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:\")

Share this post


Link to post
Share on other sites
SpookMeister

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]

Share this post


Link to post
Share on other sites
Jos

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?

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                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
cramaboule

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 !!!

Share this post


Link to post
Share on other sites
cramaboule

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

Share this post


Link to post
Share on other sites
Ascend4nt

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.

Share this post


Link to post
Share on other sites
monoceres

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!

Share this post


Link to post
Share on other sites
cramaboule

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

Share this post


Link to post
Share on other sites
GEOSoft

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!"

Share this post


Link to post
Share on other sites
Valik

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?

Share this post


Link to post
Share on other sites
cramaboule

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

Share this post


Link to post
Share on other sites
Ascend4nt

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)

Share this post


Link to post
Share on other sites
Valik

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:".

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.