Jump to content
Sign in to follow this  
AandDTechnology123

Parsing a file name

Recommended Posts

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

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

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

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

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

Share this post


Link to post
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

 

Share this post


Link to post
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) 

Share this post


Link to post
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

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  

×
×
  • Create New...