Graesholt Posted June 22, 2020 Share Posted June 22, 2020 Hey guys, I hope I'm posting this in the correct place. I am trying to access PathCleanupSpec in AutoIT, much in the way these things are called in the WinAPIShPath.au3 file. It's not working out. Here is some code... Local $Badstring = 'jo|h*nj/oh<n:jo>h?n"j|oh/njo*h>nj:oh"n|j*ohnj/o?hnj|o:h?njohn' Local $Goodstring = 'Placeholder' _WinAPI_PathCleanupSpec($Badstring, $Goodstring) MsgBox(0, 'john!', $Goodstring) Exit Func _WinAPI_PathCleanupSpec($sInFilePath, $sOutFilePath) MsgBox(0, 'john!', $sInFilePath & ' ' & $sOutFilePath) ; DEBUG Local $aRet = DllCall('shlobj_core.dll', 'int', 'PathCleanupSpec', 'wstr', $sInFilePath, 'wstr', $sOutFilePath) MsgBox(0, 'john!', $sInFilePath & ' ' & $sOutFilePath) ; DEBUG Return $sOutFilePath EndFunc ;==>_WinAPI_PathCleanupSpec I tried some stuff, but I feel like I might be out of my depth. Does anyone have any wisdom to share? Is it even possible? (because I'll take no for an answer in that regard...) Thank you for your time! Link to comment Share on other sites More sharing options...
jchd Posted June 22, 2020 Share Posted June 22, 2020 There are many errors in your code. First you don't follow the API specifications: read again https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-pathcleanupspec The first argument is a fully qualified valid path. The second argument is a filename to be cleaned; this string is "cleaned" on-place. The dll to use is shell32.dll as specified in the function description. You need to retrieve the changed file name from the array returned by DllCall. Working code: Local $sPath = 'D:\Placeholder\subdir' Local $sFile = 'jo|h*nj/oh<n:jo>h?n"j|oh/njo*h>nj:oh"n|j*ohnj/o?hnj|o:h?njohn' Local $sFixedFile = _WinAPI_PathCleanupSpec($sPath, $sFile) ConsoleWrite($sPath & '\' & $sFixedFile) Func _WinAPI_PathCleanupSpec($sPathName, $sFileName) Local $aRet = DllCall('shell32.dll', 'int', 'PathCleanupSpec', 'wstr', $sPathName, 'wstr', $sFileName) Return $aRet[2] EndFunc ;==>_WinAPI_PathCleanupSpec This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
water Posted June 22, 2020 Share Posted June 22, 2020 Welcome to AutoIt and the forum! As far as I understand DLLCall you should check for errors after the call (@error <> 0) get the result of the function returned in an array This is described in the help file. BTW: "It's not working out." doesn't help much. Describe what you expect and what you get as a result (wrong string, error code etc.) My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Graesholt Posted June 22, 2020 Author Share Posted June 22, 2020 Fair critisism. In this small example, what I want to happen is have a string returned without any special characters (This string would be "johnjohnjohnjohnjohnjohnjohnjohnjohnjohn"). This is not working out, by it not seeming to change the string at all. Sorry for leaving this out. I will do my best to attempt to apply your advice... Link to comment Share on other sites More sharing options...
jchd Posted June 22, 2020 Share Posted June 22, 2020 (edited) Did you at least run my code? Another way to achieve the same thing PathCleanupSpec() does (except the 8.3 part, but who uses old-FAT now?): Local $sPath = 'D:\Placeholder\subdir' Local $sFile = 'jo|h*nj/oh<n:jo>h?n"j|oh/njo*h>nj:oh"n|j*ohnj/o?hnj|o:h?n\john' Local $sFixedFile = StringRegExpReplace(StringReplace($sFile, '/', '-'), '[\\:*?"<>|]', '') ConsoleWrite($sPath & '\' & $sFixedFile & @LF) Local $sFixedFile = _WinAPI_PathCleanupSpec($sPath, $sFile) ConsoleWrite($sPath & '\' & $sFixedFile & @LF) Func _WinAPI_PathCleanupSpec($sPathName, $sFileName) Local $aRet = DllCall('shell32.dll', 'int', 'PathCleanupSpec', 'wstr', $sPathName, 'wstr', $sFileName) Return $aRet[2] EndFunc ;==>_WinAPI_PathCleanupSpec If you insist on removing forward slashes instead of replacing them by a dash, then simply use this: Local $sPath = 'D:\Placeholder\subdir' Local $sFile = 'jo|h*nj/oh<n:jo>h?n"j|oh/njo*h>nj:oh"n|j*ohnj/o?hnj|o:h?n\john' Local $sFixedFile = StringRegExpReplace($sFile, '[\\/:*?"<>|]', '') ConsoleWrite($sPath & '\' & $sFixedFile & @LF) Edited June 22, 2020 by jchd Forgot the 8.3 case This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 22, 2020 Moderators Share Posted June 22, 2020 (edited) Graesholt, The path returned from the DLL call is : Quote johnj-ohnjohnjoh-njohnjohnjohnj-ohnjohnjohn+ all the remaining characters are legal in a Windows filename, so the call is doing exactly what you ask it to do. if you want to get rid of all non-alphabetic characters then you need a RegEx like this: Local $sFile = 'jo|h*nj/oh<n:jo>h?n"j|oh/njo*h>nj:oh"n|j*ohnj/o?hnj|o:h?njohn' Local $sCleaned = StringRegExpReplace($sFile, "[^[:alpha:]]", "") ConsoleWrite($sCleaned & @CRLF) But no doubt a RegEx guru will be along soon to tell me there is a better way - as usual! M23 Edit: Or even before I get around to posting! Edited June 22, 2020 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
jchd Posted June 22, 2020 Share Posted June 22, 2020 To be honest, the real truth is a bit more involved. Windows is Unicode-aware and supports a very large number of characters in filenames (I'm restricting to FAT32 and NTFS here, of course). [:alpha:] isn't enough as it wouldn't allow the dot(s) of extension(s) as well as many other commonly used characters like - or _ and many others. Yet not all symbols are valid in filenames. FileWrite("e=mc².123€.©®.⅜+⅝=1.‟†‡”.ℙℚℝℤℕ.47Ω.txt", "Eureka") works fine but not all symbols do. Ideally one would also need to filter out many Unicode control characters and possibly more things. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Graesholt Posted June 22, 2020 Author Share Posted June 22, 2020 jchd, I don't know what happened, the error was probably on my end, but I didn't see your first response when I responded myself (thus I only intended to respond to water). My sincere apologies. But oh my holy stars, thanks a bunch, man! You really broke this one down to a level I could follow. Thank you so much for your time, everyone, and have a GREAT day! Link to comment Share on other sites More sharing options...
jchd Posted June 22, 2020 Share Posted June 22, 2020 No worry. Glad it works for you. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) 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