AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Need a way to get the position for a backslash in a string

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
laserman



Joined: 21 Jan 2008
Posts: 9

PostPosted: Wed Aug 06, 2008 3:16 pm    Post subject: Need a way to get the position for a backslash in a string Reply with quote

I am trying to take the file name only (no extention, no path) out of a path name.
Because I am running a loop where the path can change the script contains StringGetPos to get the position of the last backslash.
StringTrimLeft then removes the path and leaves me with the file name.

The problem I am having is trying to get a position on the backslash.
I am getting an error that the backslash is an illegal character.

Does anybody know a way (accent mark, etc.) to allow the backslash to be used?

Code:
;This Script will batch convert .prt files to .dxf files using Metalsoft exporter
;Metalsoft exporter will normally only convert one file at a time
FileSelectFolder, MyFolder
Msgbox, %MyFolder%
if ErrorLevel = 1
    Exit
else
FileSelectFolder, DestFolder
if ErrorLevel = 1
    Exit
else
SetWorkingDir, %Myfolder%
Loop, %Myfolder%\*.prt, 0, 0
    {
     Tooltip % A_TickCount
     Sleep, 10
     Msgbox, %A_LoopFileFullPath%
     StringGetPos, Position, %A_LoopFileFullPath%, (\), R1       ; Get the Position of the last backslash
     Msgbox, %Position%
     IfWinNotExist, METALSOFT Exporter     
       {
        Run C:\Unfold3d\FabriWIN\EXPGR.EXE
        WinWaitActive, METALSOFT Exporter
       }
     IfWinNotActive, METALSOFT Exporter
       {
        WinActivate, METALSOFT Exporter
        WinWaitActive, METALSOFT Exporter
       }
     StringTrimLeft, DXFfilename, A_LoopFileFullPath, %Position%       ; Trims off entire path
     StringTrimRight, DXFfilename, DXFfilename, 4                      ; Trims off entire ext
     IfExist, %DestFolder%\%DXFfilename%
        Continue
     else
     Send !l
     WinWait, Open            ; Opens The File to Export
     WinWaitActive, Open
     Sleep 100
     Send %A_LoopFileFullPath%
     Sleep 100
     Send {enter}
     WinWaitClose, Open
     Send !E               ; Opens Export To Window
     WinWait, Exporter Controls
     WinWaitActive, Exporter Controls
     MouseClick, Left, 317, 255,         ; Select DXF file type
     Sleep 100                        
     MouseClick, Left, 156, 288,                            
     Sleep 100                                             
     MouseClick, Left, 211, 227,         ; Select in input box
     Send {Home}                                            
     Send +{End}                                             
     Sleep 100
     Send %DestFolder%\%DXFfilename%
     Send {enter}
     Sleep 300
     IfWinExist, Exporter Warning
     Send {enter}
     WinWaitNotActive, Exporter Controls
     }
Pause::Pause
;
; AutoHotkey Version: 1.0.47.06
; Language:       English
; Platform:       Win XP
; Author:         anybody
;
; Script Function:
;   Template script (you can customize this template by editing "ShellNew\Template.ahk" in your Windows folder)
;

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

Back to top
View user's profile Send private message
scottmattes



Joined: 21 May 2007
Posts: 98
Location: USA

PostPosted: Wed Aug 06, 2008 3:55 pm    Post subject: Reply with quote

SplitPath

--------------------------------------------------------------------------------

Separates a file name or URL into its name, directory, extension, and drive.

SplitPath, InputVar [, OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive]
_________________
-------------
Scott Mattes

My small, but growing, collection of scripts.
Back to top
View user's profile Send private message Visit poster's website
laserman



Joined: 21 Jan 2008
Posts: 9

PostPosted: Wed Aug 06, 2008 4:39 pm    Post subject: Reply with quote

Thanks Matt,
I've used that before but didn't think of it, thanks for the help.
Back to top
View user's profile Send private message
[VxE]



Joined: 07 Oct 2006
Posts: 1496

PostPosted: Wed Aug 06, 2008 8:56 pm    Post subject: Reply with quote

Code:
msgbox % SubStr(A_MyDocuments, InStr(A_MyDocuments, "\", 0, 0)+1)
; replace the text in red with any file path to get the part after the last backslash

Is the non-regex way to do the same thing inside an expression.
_________________
My Home Thread
More Common Answers: [1]. It's in the FAQ [2]. Ternary ( a ? b : c ) guide [3]. Post code inside [code][/code] tags !
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group