emmanuel Posted July 7, 2006 Posted July 7, 2006 I feel like a newb all over again, it's fun getting back into autoit, but... now I'm all newb-ish all over again. What I want to do is prepend "[iRLARD] " to the begining of a file name. I know I'm doing it wrong now, the output now would be "[iRLARD] c:\path\pic.jpg" I want it to be "c:\path\[iRLARD] pic.jpg" this was supposed to be fast and easy.... if $CmdLine[0] = 1 Then FileCopy( $CmdLine[1], "[IRLARD] "& $CmdLine[1]) Else MsgBox(0,"[IRLARD] It!", "IRLARD it will prepend [IRLARD] to a file that is dropped on the EXE or run as a command ie: ""[irlard] it.exe"" pic.jpg will copy pic.jpg to ""[IRLARD] pic.jpg""") EndIf So, I swear there used to be an UDF that would break a path into an array for use of it's part, but I can't find it now... I think Valik or Larry wrote it... Does anyone remember it, or have it? Thanks! P.S. Hi everyone! "I'm not even supposed to be here today!" -Dante (Hicks)
Moderators SmOke_N Posted July 7, 2006 Moderators Posted July 7, 2006 I feel like a newb all over again, it's fun getting back into autoit, but... now I'm all newb-ish all over again. What I want to do is prepend "[iRLARD] " to the begining of a file name. I know I'm doing it wrong now, the output now would be "[iRLARD] c:\path\pic.jpg" I want it to be "c:\path\[iRLARD] pic.jpg" this was supposed to be fast and easy.... if $CmdLine[0] = 1 Then FileCopy( $CmdLine[1], "[IRLARD] "& $CmdLine[1]) Else MsgBox(0,"[IRLARD] It!", "IRLARD it will prepend [IRLARD] to a file that is dropped on the EXE or run as a command ie: ""[irlard] it.exe"" pic.jpg will copy pic.jpg to ""[IRLARD] pic.jpg""") EndIf So, I swear there used to be an UDF that would break a path into an array for use of it's part, but I can't find it now... I think Valik or Larry wrote it... Does anyone remember it, or have it? Thanks! P.S. Hi everyone!Hi Emmanuel, take a look at the Beta and _PathSplit() in the Beta Help, that will do what you want. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
emmanuel Posted July 8, 2006 Author Posted July 8, 2006 Wow, 2 years since I've been active and its still in the beta ... Thanks, I'll check it out from home, even though I got it with some simple string work. Will post my fixed code. "I'm not even supposed to be here today!" -Dante (Hicks)
PsaltyDS Posted July 8, 2006 Posted July 8, 2006 (edited) Wow, 2 years since I've been active and its still in the beta ... Thanks, I'll check it out from home, even though I got it with some simple string work. Will post my fixed code. The ref variable for the directory and array [2] generated by _PathSplit() still has the entire directory portion in one element, so you might want to further break it down with StringSplit(): #include <file.au3> #include <array.au3> Dim $sSplitDrv, $sSplitDir, $sSplitFile, $sSplitExt $TestPath = "C:\MyDir\MySubDir\MySub-SubDir\MyFile.ext" $aSplitPath = _PathSplit($TestPath, $sSplitDrv, $sSplitDir, $sSplitFile, $sSplitExt) _ArrayDisplay($aSplitPath, "_PathSplit() Results") $aSplitDir = StringSplit($sSplitDir, "\") _ArrayDisplay($aSplitDir, "StringSplit() Results")oÝ÷ Øô·«y§bazâ)Ú{*.)'hmqªÞiº.¶ÊeÛbayØ«yËh¯*h®Ø¨Êj{-Y]¢+pØh¶¸§*e×ë¢cë¡Ö§vz"Énuíý²'ò¢ç^²*Þjëh×6$TestPath = "C:\MyDir\MySubDir\MySub-SubDir\MyFile.ext" $aSplitPath = StringSplit($TestPath, "\") $aSplitPath[$aSplitPath[0]] = "[IRLARD] " & $aSplitPath[$aSplitPath[0]] $NewPath = $aSplitPath[1] For $n = 2 To $aSplitPath[0] $NewPath = $NewPath & "\" & $aSplitPath[$n] Next MsgBox(64, "Results", "Input $TestPath = " & $TestPath & @CRLF & _ "Output $NewPath = " & $NewPath) Edited July 8, 2006 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
emmanuel Posted July 8, 2006 Author Posted July 8, 2006 (edited) P.S. On re-reading the original I see you likely don't care about splitting the directory portion. But you can still do it with only StringSplit() from Prod, and no #include's, if you desire: Coolness, pretty different from what I did. Here's what I'd figured out while sitting at the bus stop on my laptop offline:if $CmdLine[0] = 1 Then $sFullPath = $CmdLine[1] $iLastWhack = StringInStr($sFullPath,"\",0,-1) $sPath = StringLeft($sFullPath,$iLastWhack) $sFileNameLen = StringLen($sFullPath) - StringLen($sPath) $sFileName = StringRight($sFullPath, $sFileNameLen) ;MsgBox (0,"",$sPath & @CR & $sFileName) if MsgBox(1, "[IRLARD] It!", "Copying """ & $sFullPath & '"' & @cr & 'to: "' & $sPath & "[IRLARD] " & $sFileName & @crlf& _ "Go post it like a retard!",2) = 2 Then Exit(1) EndIf FileCopy( $sFullPath, $sPath & "[IRLARD] " & $sFileName) Else MsgBox(0,"[IRLARD] It!", "IRLARD it will prepend [IRLARD] to a file that is dropped on the EXE or run as a command ie: ""[irlard] it.exe"" pic.jpg will copy pic.jpg to ""[IRLARD] pic.jpg""") EndIf Now, if I wanted to update it so that if someone dropped a bunch of files on there, all I'd have to do is do a for loop, for as many as $CmdLine[0] to do the same thing for each one, right? Edited July 8, 2006 by emmanuel "I'm not even supposed to be here today!" -Dante (Hicks)
MHz Posted July 8, 2006 Posted July 8, 2006 Now, if I wanted to update it so that if someone dropped a bunch of files on there, all I'd have to do is do a for loop, for as many as $CmdLine[0] to do the same thing for each one, right?Hi emmanuel, it has sure been awhile. I did not scutinize your code but only adapted to your Cmdline request. Yes, that is the technique if $CmdLine[0] Then For $i = 1 To $CmdLine[0] $sFullPath = $CmdLine[$i] $iLastWhack = StringInStr($sFullPath,"\",0,-1) $sPath = StringLeft($sFullPath,$iLastWhack) $sFileNameLen = StringLen($sFullPath) - StringLen($sPath) $sFileName = StringRight($sFullPath, $sFileNameLen) ;MsgBox (0,"",$sPath & @CR & $sFileName) if MsgBox(1, "[IRLARD] It!", "Copying """ & $sFullPath & '"' & @cr & 'to: "' & $sPath & "[IRLARD] " & $sFileName & @crlf& _ "Go post it like a retard!",2) = 2 Then Exit(1) EndIf FileCopy( $sFullPath, $sPath & "[IRLARD] " & $sFileName) Next Else MsgBox(0,"[IRLARD] It!", "IRLARD it will prepend [IRLARD] to a file that is dropped on the EXE or run as a command ie: ""[irlard] it.exe"" pic.jpg will copy pic.jpg to ""[IRLARD] pic.jpg""") EndIf
emmanuel Posted July 8, 2006 Author Posted July 8, 2006 That did the trick, thanks MHz!Hi emmanuel, it has sure been awhile.I did not scutinize your code but only adapted to your Cmdline request. Yes, that is the techniqueI think I'll be around more often as I take a more blended approach to scripting and packaging apps... "I'm not even supposed to be here today!" -Dante (Hicks)
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