Jump to content

Parsing a file name


Recommended Posts

  • Moderators

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?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

Look in the help file for StringSplit, it will do what you want. Use "_" as the delimiter to split on.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

  • Moderators

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 :)

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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) 
Link to comment
Share on other sites

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...