Jump to content
Sign in to follow this  
AandDTechnology123

Parsing a file name

Recommended Posts

AandDTechnology123

What I want to do is create a script that will parse a specific file name. I want to create 3 strings to hold values from the parsed values then I need to move to a new directory. Thanks for the help.

Share this post


Link to post
Share on other sites
JLogan3o13

Thanks for the lack of information. Can you please give an idea of what the filename looks like, and what you would like the resultant 3 strings to look like?


√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
AandDTechnology123

The file name would be 1234ABC_DEF_GHI, I would want the the strings to be string1=1234ABC, string2=DEF and string3=GHI. I have a directory with may files so it will be given a specific directory to find a file parse the file name and the create a new directory depending on the parsed stings. Thanks for you help.

Share this post


Link to post
Share on other sites
AandDTechnology123

Great thanks, now how do I get the file name into a string?

Share this post


Link to post
Share on other sites
computergroove

Is the filename a file in a directory? Is it the only file in the directory? Do you need to do this with only new files that show up and are they deleted after they are processed by your script?


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites
AandDTechnology123

Yes the filename is in a directory C:TempSUPPORT1234ABC_DEF_GHI.dat.

There are up to 50 files in a given directory.

This will be will old and new files, the first time it is ran it will have old files and thereafter will be new files, yes they will be deleted after moving them to a new directory and also making a backup file.

Share this post


Link to post
Share on other sites
MikahS

Concatenation I presume.

$fullString = $string1 + $string2 + $string3

 

Yours would not look exactly like this, as string split returns an array, not individual string variables.


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites
JLogan3o13

AandDTechnology123, may I suggest you break this down into pieces. Take the first step first - look at Stringsplit, run the example, and then try to duplicate for your own needs. Then post what you have here, and we can help with the rest. But there is no point in talking to you about all the different ways to accomplish step 5 if you have yet to complete step 1 :)


√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
AandDTechnology123

Step 1 is to get the filename into a string to parse and I can not find anything in the help to direct me.

Share this post


Link to post
Share on other sites
kylomas

Look at the _filelist* functions in your Help file...


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
MikahS

Manually.. Hopefully this gets you to understand the steps needed..

Local $strOpen, $strSplit, $i, $strName

$strOpen = FileOpenDialog("get file", @WorkingDir, "all(*.*)") ; select the file you want
$strSplit = StringSplit($strOpen, "\") ; split it by \
$i = $strSplit[0] ; get the last value
$strName = $strSplit[$i] ; set the file name
MsgBox(0, "", $strName) ; tell us
Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites
mikell

Maybe replace in kylomas's comment the * by ToArray()

:D

Share this post


Link to post
Share on other sites
kylomas

Or ToArrayRec(), hence the *...


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
AandDTechnology123

I now have it so I can parse my files but now I am having an issue with StringSplit, it is adding a 1 to the beginning of the first string. Any ideas?

$strSplit = StringSplit($aTrimFileName, "_") 
$aEngineSerialNumber = $strSplit[1] 
$aLogType = $strSplit[2] 
$aLogDescription = $strSplit[3] 
MsgBox(0, "", $aEngineSerialNumber)
MsgBox(0, "", $aLogType)
MsgBox(0, "", $aLogDescription) 

Share this post


Link to post
Share on other sites
kylomas

Works for me...

local $aTrimFileName = '1234ABC_DEF_GHI'

$strSplit = StringSplit($aTrimFileName, "_")
$aEngineSerialNumber = $strSplit[1]
$aLogType = $strSplit[2]
$aLogDescription = $strSplit[3]
MsgBox(0, "", $aEngineSerialNumber)
MsgBox(0, "", $aLogType)
MsgBox(0, "", $aLogDescription)

Note - "a" is the defacto prefix for arrays.  Your var names are misleading.


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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  

×