eignxing Posted July 25, 2006 Share Posted July 25, 2006 I was having a hard time with the _RunDos parameter because I couldn't use things like @workingdir. This function makes things a lot easier. It isn't 100% foolproof, but as long as you don't have too many strange characters or multiple folders with the same name, then it should work okay. expandcollapse popup$filepath = "C:\Documents and Settings\User\Desktop\New Folder" $dospath = DosPath($filepath) MsgBox(0, "", $filepath&@LF&$dospath) Func DosPath($filepath) ;Returns DOS compatible file path $i = 1 $1 = StringUpper($filepath) Do $2 = StringInStr($1, "\", 0, $i) $3 = StringInStr($1, "\", 0, $i+1) $4 = StringMid($1, $2+1, $3-$2-1) If $4 = "" Then ExitLoop EndIf $5 = StringStripWS($4, 8) If StringInStr($5, ".") <> 0 Then $5 = StringReplace($5,".","") $6 = StringLen($5) ElseIf StringInStr($5, ';') <> 0 Then $5 = StringReplace($5,';',"_") $6 = StringLen($5) ElseIf StringInStr($5, '[') <> 0 Then $5 = StringReplace($5,'[',"_") $6 = StringLen($5) ElseIf StringInStr($5, ']') <> 0 Then $5 = StringReplace($5,']',"_") $6 = StringLen($5) ElseIf StringInStr($5, '=') <> 0 Then $5 = StringReplace($5,'=',"_") $6 = StringLen($5) ElseIf StringInStr($5, ',') <> 0 Then $5 = StringReplace($5,',',"_") $6 = StringLen($5) ElseIf StringInStr($5, "") = 0 Then $6 = StringLen($5) EndIf If $6 > 8 Then $7 = StringLeft($5, 6) $8 = String($7&"~1") $1 = StringReplace($1, $4, $8) EndIf $i = $i + 1 Until StringInStr($1, "\", 0, $i) = 0 Return $1 EndFunc Link to comment Share on other sites More sharing options...
MHz Posted July 25, 2006 Share Posted July 25, 2006 Welcome, and thanks for sharing.This is based on 8.3 filenames? Then FileGetShortName() maybe more convenient and more reliable?Form your test, if you have "New Folder" and "New FolderA" in the same path and use the latter, then your UDF will return "C:\DOCUME~1\USER\DESKTOP\NEWFOL~1" instead of the expected "C:\DOCUME~1\USER\DESKTOP\NEWFOL~2". Notice the last integer changes as 8.3 filenames need to be generated for the last number to be correct as is done by windows API.Nice try, but you would need alot more string handling to get the correct result. Using quotes around the path is another option to avoid problems with spaces in paths. Link to comment Share on other sites More sharing options...
eignxing Posted July 25, 2006 Author Share Posted July 25, 2006 Thanks, I didn't know about that! Link to comment Share on other sites More sharing options...
MHz Posted July 25, 2006 Share Posted July 25, 2006 (edited) No problem. Hey, was your 1st post, you deserve a chance. Just tested, but maybe need more. This may will do as a possible UDF other then the builtin FileGetShortName(). $filename = "C:\Program Files\Internet Explorer\IEXPLORE.EXE" $rc = DllCall("kernel32.dll", "int", "GetShortPathName", "str", $filename, "str", "", "int", 260) MsgBox(0, "title", $rc[2]) The path to the file needs to exist for it to work. Edited July 25, 2006 by MHz Link to comment Share on other sites More sharing options...
iceberg Posted September 11, 2006 Share Posted September 11, 2006 hi Mhz, thanks for your last code. helped me in another project i was doing. mouse not found....scroll any mouse to continue. Link to comment Share on other sites More sharing options...
xandre Posted February 18, 2016 Share Posted February 18, 2016 Hi MHz, I am having trouble while trying to convert a specific folder name using both methods described above (which worked great the rest of time ) Folder is named as follows: "C:\some_path\UPP-A.2 #5 FBF2" The result of GetShortPathName() call is: "C:\some_p~1\UPP-A~1.2 #5" Which turns out to be invalid path... At first I wondered if the '#' was causing the issue. But it turns out that "C:\some_path\UPP-A.2 FBF2" get converted to "C:\some_path\UPP-A~1.2FB" Is this a bug? Should I be escaping/replacing the space characters first? Link to comment Share on other sites More sharing options...
xandre Posted February 19, 2016 Share Posted February 19, 2016 Never mind. For some reason, depending on this folder location the outcome is different: - It is consistent GetShortPathName() called from autoit script, no matter where it is located. - However, using the output 8.3 path string in dosbox emulator emulator to change working directory sometimes works (i.e. cd into the right folder which contains the right file) and sometimes cd takes me into a seemingly empty folder... The weird thing is that dosbox allows me to cd in this folder while it is not listed if I do a DIR in the parent folder. Anyway the issue is definitely not autoit related: Humble apologize for polluting this forum with irrelevant stuff. Link to comment Share on other sites More sharing options...
TheSaint Posted February 19, 2016 Share Posted February 19, 2016 @xandre - Welcome to the forum. You do realize this topic was last replied to over 9 years ago. If you are having trouble with something, you should use General Help & Support forum, and provide a link back to this topic if necessary. You'll get many more eyes and minds on your problem there. I could not tell from what you wrote, whether you actually tried the AutoIt function 'FileGetShortName' or just tried the two pieces of code in this topic. See the Help file or documentation if need be. Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) 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