AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Trimming And Splitting Strings In Files

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Puzzled Greatly



Joined: 15 Aug 2009
Posts: 274

PostPosted: Sun Jan 03, 2010 12:05 am    Post subject: Trimming And Splitting Strings In Files Reply with quote

Hello,

I've cobbled together a script that lists the files in a chosen directory:
Code:
FileSelectFolder, FolderName, , 3, Folder Contents - Choose a folder
if FolderName =
   MsgBox, You didn't choose a folder.
else
  {
  SplitPath,A_LoopFileLongPath,FileNameNoExt ;Extract Directory,filename, and extension
 
 
    WordList =
    Loop, %FolderName%\*.*, 0, 0
        WordList = %WordList%%A_LoopFileName%`n

    SplitPath, FolderName, OutFileName
    FileName = C:\Documents and Settings\All Users\Desktop\%OutFileName%.txt

    FileAppend, %WordList%, %FileName%
   
   
   FileRead, Contents, %FileName%
   if not ErrorLevel  ; Successfully loaded.
{
    Sort, Contents
    FileDelete, %FileName%
    FileAppend, %Contents%, %FileName%
    Contents =  ; Free the memory.
}
   
   
    run, Notepad %FileName%
  }

What I want to do is strip out the extension and then split each line into individual words. I looked at StringTrimRight but couldn't work out how to use it on each line. I'm sure it's a basic loop but I'm stuck. Help appreciated.

Thanks,

GP
Back to top
View user's profile Send private message
Puzzled Greatly



Joined: 15 Aug 2009
Posts: 274

PostPosted: Sun Jan 03, 2010 2:56 am    Post subject: Reply with quote

Hello again,

I've figured out how to strip out the extension:
Code:
FileSelectFolder, FolderName, , 3, Folder Contents - Choose a folder
if FolderName =
   MsgBox, You didn't choose a folder.
else
  {
 
    Loop, %FolderName%\*.*, 0, 0
        WordList = %WordList%%A_LoopFileName%`n

    SplitPath, FolderName, OutFileName
    FileName = C:\Documents and Settings\All Users\Desktop\%OutFileName%.txt
   
   
    FileAppend, %WordList%, %FileName%.new
   
   Loop, Read, %FileName%.new, %FileName%.tem
  {
  StringTrimRight, trimExt, A_LoopReadLine, 4
      FileAppend, %trimExt%`n
  }
   FileMove, %FileName%.tem, %FileName%, 1
   
         
   FileRead, Contents, %FileName%
   if not ErrorLevel  ; Successfully loaded.
{
    Sort, Contents
    FileDelete, %FileName%
    FileAppend, %Contents%, %FileName%
    Contents =  ; Free the memory.
}
   
   
    run, Notepad %FileName%
  }

No I want to break up each line into individual words and create a file with one word on each line. I've looked at Stringsplit but teh example with the messge box doesn't make much sense to me. How do I get every single word?

Thanks,

GP
Back to top
View user's profile Send private message
Puzzled Greatly



Joined: 15 Aug 2009
Posts: 274

PostPosted: Sun Jan 03, 2010 4:47 am    Post subject: Reply with quote

I found a solution without using SplitString - just replacing the spaces with new lines was sufficient.

GW
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group