Chimaera Posted August 11, 2012 Share Posted August 11, 2012 Been looking through all my saved stuff trying to find a piece of code that removes a trailing slash on the end of a local address. Trouble is in the early days i didnt comment all my stuff as i used it and i cant find the piece Now i did find this in my folders but im not sure what it does, even with the help file, it has something to do with \ StringRegExpReplace($soft_path, "^(.*)\\.*$", "$1\\") Does this remove the trailing slash? Problem is i get some links with a "\" and some without What im after is if i had Z:\Lessons\It would make it Z:\Lessons Or Z: etc Or the other way round so that i get a consistent approach to the location and then can add the slash after manually so i can guarantee it works If Ive just helped you ... miracles do happen. Chimaera CopyRobo() * Hidden Admin Account Enabler * Software Location From Registry * Find Display Resolution * _ChangeServices() Link to comment Share on other sites More sharing options...
guinness Posted August 11, 2012 Share Posted August 11, 2012 Look at getdirectoryformat in my signature. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Chimaera Posted August 11, 2012 Author Share Posted August 11, 2012 (edited) Thanks for that but not working for some reason Here is a reproducer so you can see what im doing $sDestSelect = FileSelectFolder("Choose a drive.", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}") _GetDirectoryFormat($sDestSelect, 1) $sDestination = $sDestSelect & @UserName & "" & @MDAY & "." & @MON & "." & @YEAR If you click a root it still shows C: If you go deeper it doesn't add the username etc properly and i end up with a missing Eg below Z:Jez11.08.2012 Z:LessonsJez11.08.2012 Im wondering if its to do with the file select folder bit Edited August 11, 2012 by Chimaera If Ive just helped you ... miracles do happen. Chimaera CopyRobo() * Hidden Admin Account Enabler * Software Location From Registry * Find Display Resolution * _ChangeServices() Link to comment Share on other sites More sharing options...
GEOSoft Posted August 11, 2012 Share Posted August 11, 2012 (edited) That removes the last backslash and everything after it then adds the backslash in again although it would be better written with (.+) instead of (.*) although in the case of a folder path it won't really matter. What are you trying to get? Edited August 11, 2012 by GEOSoft 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...
Chimaera Posted August 11, 2012 Author Share Posted August 11, 2012 (edited) Hi George Im trying to get this $sDestSelect = FileSelectFolder("Choose a drive.", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}") $sDestination = $sDestSelect & @UserName & "" & @MDAY & "." & @MON & "." & @YEAR So if i click a top level in th file select folder window It gives me C: Or If i go lower For example C:Lessons It then adds the before adding this to the end of it @UserName & "" & @MDAY & "." & @MON & "." & @YEAR I think the origanal i posted was probably one of yours StringRegExpReplace($soft_path, "^(.*).*$", "$1") To sum up im trying to make sure at the end of $sDestSelect It has a before i add the extra folder info Edited August 11, 2012 by Chimaera If Ive just helped you ... miracles do happen. Chimaera CopyRobo() * Hidden Admin Account Enabler * Software Location From Registry * Find Display Resolution * _ChangeServices() Link to comment Share on other sites More sharing options...
GEOSoft Posted August 11, 2012 Share Posted August 11, 2012 Thats what it should be doing as it sits now except it will also remove the last folder in the path if there is no trailing backslash. Will the paths always be just folders or will you be pointing to a file and getting back the folder structure? That's what that regex is designed to do. If they are always folders then you don't need a regexp. If NOT StringRight($sDestSelect, 1) = "" Then $sDestSelect &= "" You could also check that it is a folder with FileGetAttrib() 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...
Chimaera Posted August 11, 2012 Author Share Posted August 11, 2012 (edited) Its basically selecting a drive or a folder to backup no files I started with this on a fresh sheet and it still doesn't work Is this a bug? $sDestSelect = FileSelectFolder("Choose a drive.", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}") If NOT StringRight($sDestSelect, 1) = "" Then $sDestSelect &= "" $sDestination = $sDestSelect & @UserName & "" & @MDAY & "." & @MON & "." & @YEAR ConsoleWrite($sDestination & @CRLF) If you select just C for eg you get C:Jez11.08.2012If i doubleclick c and go a folder below it then i get this C:ATIJez11.08.2012 There is supposed to be a between ATI & Jez eg ATIJez Can anyone else make this happen? Btw im win 7 64 bit not that it should matter really Edited August 11, 2012 by Chimaera If Ive just helped you ... miracles do happen. Chimaera CopyRobo() * Hidden Admin Account Enabler * Software Location From Registry * Find Display Resolution * _ChangeServices() Link to comment Share on other sites More sharing options...
GEOSoft Posted August 11, 2012 Share Posted August 11, 2012 I screwed up. This works $sDestSelect = FileSelectFolder("Choose a drive.", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}") If StringRight($sDestSelect, 1) <> "" Then $sDestSelect &= "" $sDestination = $sDestSelect & @UserName & "" & @MDAY & "." & @MON & "." & @YEAR ConsoleWrite($sDestination & @CRLF) And this also works $sDestSelect = FileSelectFolder("Choose a drive.", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}") If StringRegExp($sDestSelect, "^.+[[:alnum:]]$") Then $sDestSelect &= "" $sDestination = $sDestSelect & @UserName & "" & @MDAY & "." & @MON & "." & @YEAR ConsoleWrite($sDestination & @CRLF) and that would be considered abuse of a RegEx. But the really good news is that FileSelectFolder() never adds the backslash so you don't even have to check for it. $sDestination = FileSelectFolder("Choose a drive.", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}") & "" & @UserName & "" & @MDAY & "." & @MON & "." & @YEAR If @Error Then ;; In case someone clicks the cancel button or closes the FileSelectFolder() window ConsoleWrite("Error" & @CRLF) Else ConsoleWrite($sDestination & @CRLF) EndIf 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...
guinness Posted August 11, 2012 Share Posted August 11, 2012 The reason is Forum Software!! It removed the backslash in my SRE that's why it didn't work, darn. I have updated it. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Chimaera Posted August 11, 2012 Author Share Posted August 11, 2012 (edited) Thx guys at least its not me going crazy lolThis worked for me$sDestSelect = FileSelectFolder("Choose a drive.", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}") If StringRight($sDestSelect, 1) <> "" Then $sDestSelect &= "" $sDestination = $sDestSelect & @UserName & "" & @MDAY & "." & @MON & "." & @YEAR ConsoleWrite($sDestination & @CRLF)However this one did not$sDestination = FileSelectFolder("Choose a drive.", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}") & "" & @UserName & "" & @MDAY & "." & @MON & "." & @YEAR If @Error Then ;; In case someone clicks the cancel button or closes the FileSelectFolder() window ConsoleWrite("Error" & @CRLF) Else ConsoleWrite($sDestination & @CRLF) EndIfIf you select just C: for eg it gives a double in the pathegC:Jez11.08.2012But either way it appears to be sortedThx again Edited August 11, 2012 by Chimaera If Ive just helped you ... miracles do happen. Chimaera CopyRobo() * Hidden Admin Account Enabler * Software Location From Registry * Find Display Resolution * _ChangeServices() Link to comment Share on other sites More sharing options...
GEOSoft Posted August 11, 2012 Share Posted August 11, 2012 First thing to learn about SREs is when to use them and this wasn't something that required it at all but this would have worked fine $sDestination = StringRegExpReplace(FileSelectFolder("Choose a drive.", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"), "(.)?$", "$1") & @UserName & "" & @MDAY & "." & @MON & "." & @YEAR 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...
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