# Removing Directory Information

## Recommended Posts

I need to build a script that takes input given by another program (as for example c:\temp\test.txt) and takes the file name out (example would be "test" without quotes) to then pass the data to another application with a different directory for output.

So, it would look like for example:

txt2doc c:\temp\test.txt c:\storage\test.doc

Now the input directory is doesn't vary neither does the output directory, so I could do something like $S to equal the file name part (in the example, "test") and it can look something like txt2doc c:\temp\$S.doc c:\storage\$S.doc Or I can just get an Autoit to trim off all the directory and file type information, just the raw file name and then use a bat file or something to fill in the non$S parts.

How do I take the file and trim it down, then take the trimmed data and pass it to an application?

##### Share on other sites

$a = "c:\i am\a path and a\file.txt"$file = StringTrimLeft(StringInStr($a,"\",0,-1) MsgBox(4096,"",$file)

$file = StringLeft($file,StringInStr($file,".")-1) MsgBox(4096,"",$file)

<{POST_SNAPBACK}>

MsgBox(4096,"",$file)$a can come from anywhere $CmdLine, IniRead()... whatever... Lar. <{POST_SNAPBACK}> So I would use a$CmdLine to get a$And the first StringTrimLeft I could experiment to get the number of characters to trim, since that will be constant from the left and from the right for the end part. Above, would I use StringRight and not StringLeft to come in from the right? Also to simplify, I can do an IniRead to get the source directory, which is where the file comes from, could I use StringReplace and use the ini file with the directory path to just make it blank? I am rather stupid at this so forgive me... #### Share this post ##### Link to post ##### Share on other sites You'll need to practice and read the help file... StringInStr can check for an instance of a character or string starting from the left OR right...$a = StringLeft($a,StringInStr($a,".".0.-1) - 1)

the above will trim evryhing to the right of and including the "." of a string ($a).$a can come from a parameter passed to the script via the command line ($CmdLine[1]) or from IniRead...$a = IniRead("C:\my path\to my ini.ini","MyKeyName","MyValue")

There should be some help in the help file regarding string handling...

Lar.

<{POST_SNAPBACK}>

Thank you very much!

##### Share on other sites

You'll need to practice and read the help file... StringInStr can check for an instance of a character or string starting from the left OR right...

$a = StringLeft($a,StringInStr($a,".".0.-1) - 1) the above will trim evryhing to the right of and including the "." of a string ($a).

$a can come from a parameter passed to the script via the command line ($CmdLine[1]) or from IniRead...

$a = IniRead("C:\my path\to my ini.ini","MyKeyName","MyValue") There should be some help in the help file regarding string handling... Lar. <{POST_SNAPBACK}> I tried the following:$file=StringTrimLeft(StringInStr($a,"\",0,-1)) ; I added a second ) at the end? MsgBox(4096,"",$file)

$file=StringLeft($file,StringInStr($file,".",0,-1)-1) MsgBox(4096,"",$file)

$outputfile=$targdir & "\" & $file and ran the au3 sript to parse the outpit. It errored first on the first line above because there was not a second ). Then after the ) was added it errors at the first StringInStr in the first line above "Incorrect Number of Parameters in Function Call" What did I do wrong? #### Share this post ##### Link to post ##### Share on other sites StringTrimLeft(StringInStr($a,"\",0,-1))

should be

StringTrimLeft( $a, StringInStr($a,"\",0,-1))

<{POST_SNAPBACK}>

Beautiful, that worked great. I had before just did a character trim and counted the characters, which worked, but it was going to be harder on the "production server" as there will be up to 5-7 of the '\'

The program I am using automatically pulls the backend off and puts its own backend on, so I removed that coding even though it worked. ( I might put it back in), I also built a ',' removal string replace because the application hates ',' and I would like to put in a '.' remover, but it is very difficult.

I do have a helper appliation that pre-screens the files to remove the '.' and ',', but only specific '.' and not all '.' I think the program only chokes on dot space and not just the dot or period. The problem has been more that I cannot test the dot space part because the pass off is different in my test than the production pass off.

##### Share on other sites

Beautiful, that worked great.  I had before just did a character trim and counted the characters, which worked, but it was going to be harder on the "production server" as there will be up to 5-7 of the '\'

The program I am using automatically pulls the backend off and puts its own backend on, so I removed that coding even though it worked. ( I might put it back in),  I also built a ',' removal string replace because the application hates ',' and I would like to put in a '.' remover, but it is very difficult.

I do have a helper appliation that pre-screens the files to remove the '.' and ',', but only specific '.' and not all '.'  I think the program only chokes on dot space and not just the dot or period.  The problem has been more that I cannot test the dot space part because the pass off is different in my test than the production pass off.

<{POST_SNAPBACK}>

Fixed all problems. I just did a hard trim from the right 4 characters, then removed all periods, and that fixed the problem. Anytime a period was in the middle of the file, the script would go to the last instance from the right, but it will always be 4 characters, so I prefer it done hard coded.

Thanks for all the support and brain cell loan! Wouldn't have gotten it done without help.

## Create an account

Register a new account