cdkid Posted February 21, 2006 Share Posted February 21, 2006 Anywhoo, i got bored so i decided to make this. retrieves the directory of a given file. Func _FileGetDir($sFile) Local $s, $i $s = "" If FileExists($sFile) Then $sFile = StringSplit($sFile, "\") For $i = 1 To $sFile[0] - 1 If $i > 1 Then $s = $s & "\" & $sFile[$i] Else $s = $s & $sFile[$i] EndIf Next Return $s Else SetError(1) Return 0 EndIf EndFunc ;==>_FileGetDir I dont know if this already exists, but i couldnt find anything of the sort. I found this useful for using FileOpenDialogs, and using the previous directory. ~cdkid AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide! Link to comment Share on other sites More sharing options...
Xenobiologist Posted February 21, 2006 Share Posted February 21, 2006 Hi, I think there are many ways to do something like that, but I like your way. Maybe I can use it sometimes. So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
cjconstantine Posted February 27, 2006 Share Posted February 27, 2006 (edited) Here's my go at it... Func _FileGetDir($File) For $i = 1 To StringLen($File) If StringMid($File,$i,1) = "\" Then $Path_Len = $i Next $File = StringLeft($File,$Path_Len) Return($File) EndFunc Enjoy! *EDIT* - snipped out the part for the UNC conversion ... makes the function a little smaller (changed the function name too). Edited February 28, 2006 by cjconstantine Link to comment Share on other sites More sharing options...
Xenobiologist Posted February 27, 2006 Share Posted February 27, 2006 (edited) HI, or just something I found elsewhere in the forum. $path = "C:\folder 1\folder 2\autoit.exe" $array = StringSplit($path, "\") $path = StringTrimRight($path, StringLen($array[$array[0]])) MsgBox(0,"Path", $path) So long, Mega Edited February 27, 2006 by th.meger Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
Developers Jos Posted February 27, 2006 Developers Share Posted February 27, 2006 _PathSplit --------------------------------------------------------------------------------Splits a path into the drive, directory, file name and file extension parts. An empty string is set if a part is missing.#include <File.au3>_PathSplit($szPath, ByRef $szDrive, ByRef $szDir, ByRef $szFName, ByRef $szExt) 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...
Xenobiologist Posted February 27, 2006 Share Posted February 27, 2006 Hi, hmmh that is also cool. Then it could be something like: #include <file.au3> #include <array.au3> Dim $szDrive, $szDir, $szFName, $szExt, $path = "C:\folder 1\folder 2\autoit.exe" $array = _PathSplit ($path, $szDrive, $szDir, $szFName, $szExt) MsgBox(0, "Demo _PathSplit()", $array [1] & $array [2]) So long, Mega P.S.: But why do I have to declare all these variables? Dim $szDrive, $szDir, $szFName, $szExt? If only want to split a complete path given by $path = "C:\folder 1\folder 2\autoit.exe" ? Anyway, nice to know function. Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times 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