cramaboule Posted March 31, 2009 Share Posted March 31, 2009 (edited) 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 March 31, 2009 by cramaboule My Autoit programs: MAC Address - - Delete Temp Files - - Ping Test - - Play Video with VLC full screen dual monitors - - Set IP - - Pics Converter - - AutoUpdater - - CPU Usage - - Ending Script Nicely - - GDI+ GUI crossfades (slide transitions) - - Beamer - - Search and Search in Files - - Silent Ninite Others: Export Icons into Dll - - My website Link to comment Share on other sites More sharing options...
SpookMeister Posted March 31, 2009 Share Posted March 31, 2009 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 More sharing options...
MrMitchell Posted March 31, 2009 Share Posted March 31, 2009 Per Help File: Result of @WorkingDir does not contain a trailing backslash. You need to add your own. Link to comment Share on other sites More sharing options...
Developers Jos Posted March 31, 2009 Developers Share Posted March 31, 2009 Just test for the Right character and add the extra "\" when needed. 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 More sharing options...
cramaboule Posted March 31, 2009 Author Share Posted March 31, 2009 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:\") My Autoit programs: MAC Address - - Delete Temp Files - - Ping Test - - Play Video with VLC full screen dual monitors - - Set IP - - Pics Converter - - AutoUpdater - - CPU Usage - - Ending Script Nicely - - GDI+ GUI crossfades (slide transitions) - - Beamer - - Search and Search in Files - - Silent Ninite Others: Export Icons into Dll - - My website Link to comment Share on other sites More sharing options...
SpookMeister Posted March 31, 2009 Share Posted March 31, 2009 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 More sharing options...
Developers Jos Posted March 31, 2009 Developers Share Posted March 31, 2009 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 More sharing options...
cramaboule Posted March 31, 2009 Author Share Posted March 31, 2009 Just test for the Right character and add the extra "\" when needed.Josokay thanksWould it not be easier to return only C: with @WorkingDir. Then you always add a "\" ?just asking !!! My Autoit programs: MAC Address - - Delete Temp Files - - Ping Test - - Play Video with VLC full screen dual monitors - - Set IP - - Pics Converter - - AutoUpdater - - CPU Usage - - Ending Script Nicely - - GDI+ GUI crossfades (slide transitions) - - Beamer - - Search and Search in Files - - Silent Ninite Others: Export Icons into Dll - - My website Link to comment Share on other sites More sharing options...
cramaboule Posted March 31, 2009 Author Share Posted March 31, 2009 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.... yeeeeNo I've never seen the cmd My Autoit programs: MAC Address - - Delete Temp Files - - Ping Test - - Play Video with VLC full screen dual monitors - - Set IP - - Pics Converter - - AutoUpdater - - CPU Usage - - Ending Script Nicely - - GDI+ GUI crossfades (slide transitions) - - Beamer - - Search and Search in Files - - Silent Ninite Others: Export Icons into Dll - - My website Link to comment Share on other sites More sharing options...
Ascend4nt Posted March 31, 2009 Share Posted March 31, 2009 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. My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
monoceres Posted March 31, 2009 Share Posted March 31, 2009 okay thanksWould 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 More sharing options...
cramaboule Posted March 31, 2009 Author Share Posted March 31, 2009 (edited) 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 !!!: ShellExecute("G:\\folder\\\myprog.txt") Edited March 31, 2009 by cramaboule My Autoit programs: MAC Address - - Delete Temp Files - - Ping Test - - Play Video with VLC full screen dual monitors - - Set IP - - Pics Converter - - AutoUpdater - - CPU Usage - - Ending Script Nicely - - GDI+ GUI crossfades (slide transitions) - - Beamer - - Search and Search in Files - - Silent Ninite Others: Export Icons into Dll - - My website Link to comment Share on other sites More sharing options...
GEOSoft Posted March 31, 2009 Share Posted March 31, 2009 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 More sharing options...
Valik Posted March 31, 2009 Share Posted March 31, 2009 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 More sharing options...
cramaboule Posted March 31, 2009 Author Share Posted March 31, 2009 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 !!! It is, I presume, because I am too puristic !!!! My Autoit programs: MAC Address - - Delete Temp Files - - Ping Test - - Play Video with VLC full screen dual monitors - - Set IP - - Pics Converter - - AutoUpdater - - CPU Usage - - Ending Script Nicely - - GDI+ GUI crossfades (slide transitions) - - Beamer - - Search and Search in Files - - Silent Ninite Others: Export Icons into Dll - - My website Link to comment Share on other sites More sharing options...
Ascend4nt Posted March 31, 2009 Share Posted March 31, 2009 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) My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
Valik Posted March 31, 2009 Share Posted March 31, 2009 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now