Sign in to follow this  
Followers 0
kev51773

How to get path relative to a folder?

4 posts in this topic

Okay I have a problem with a script that I won't post here as its 804 lines long so far.

I have a function that recursively find all files ending .res, it works fine, however It finds the full path. I need to trim the path like in the following example

Script resides at = C:\Documents and Settings\username\Desktop\samplefolder

FullPath1 = C:\Documents and Settings\username\Desktop\samplefolder\data\projectname\setup\samplefile.res

FullPath2 = C:\Documents and Settings\username\Desktop\samplefolder\data\projectname\setup\test\samplefile2.res

FullPath3 = C:\Documents and Settings\username\Desktop\samplefolder\data\projectname\setup\test\test\samplefile3.res

The results I want are as follows

Result 1 = samplefile.res

Result 2 = test\samplefile.res

Result 3 = test\test\samplefile.res

Basically I need to find a path relative to (@ScriptDir & "\data\projectname\setup\")

Ive tried doing this using stringinstr or stringsplit and displaying the result is a msgbox for debugging but for some reason the script just hangs with the msgbox shown in the taskbar but not displayed on screen?

Any ideas? I could really do with finishing this script today or tommorow before I leave for xmas.

Share this post


Link to post
Share on other sites



Okay I have a problem with a script that I won't post here as its 804 lines long so far.

I have a function that recursively find all files ending .res, it works fine, however It finds the full path. I need to trim the path like in the following example

Script resides at = C:\Documents and Settings\username\Desktop\samplefolder

FullPath1 = C:\Documents and Settings\username\Desktop\samplefolder\data\projectname\setup\samplefile.res

FullPath2 = C:\Documents and Settings\username\Desktop\samplefolder\data\projectname\setup\test\samplefile2.res

FullPath3 = C:\Documents and Settings\username\Desktop\samplefolder\data\projectname\setup\test\test\samplefile3.res

The results I want are as follows

Result 1 = samplefile.res

Result 2 = test\samplefile.res

Result 3 = test\test\samplefile.res

Basically I need to find a path relative to (@ScriptDir & "\data\projectname\setup\")

Ive tried doing this using stringinstr or stringsplit and displaying the result is a msgbox for debugging but for some reason the script just hangs with the msgbox shown in the taskbar but not displayed on screen?

Any ideas? I could really do with finishing this script today or tommorow before I leave for xmas.

It should be quite simple. StringinStr should work so you must have done something wrong.

$RelativePath = StringRight(FullPath,StringLen(FullPath) -StringinStr(FullPath,@ScriptDir & "\data\projectname\setup\") - stringlen(@ScriptDir & "\data\projectname\setup\"))

or If the paths alway contain @ScriptDir & "\data\projectname\setup\" then you could say

$RelativePath = StringReplace(FullPath,@ScriptDir & "\data\projectname\setup\","")

But you need to be sure that

StringinStr(FullPath,@ScriptDir & "\data\projectname\setup\") > 0


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Thanks guys, It seems I was going about it correctly in the first place.

I was just encountering a bug in msgbox that I thought pointed to a problem elsewhere. As soon as I switched to saving the data to an array rather than displaying it in a msgbox, the problem disappeared.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0