• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Delimit a File Containing Both Returns and Line Feeds
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Delimit a File Containing Both Returns and Line Feeds


  • Subject: Delimit a File Containing Both Returns and Line Feeds
  • From: Thomas Maffucci <email@hidden>
  • Date: Wed, 22 Aug 2018 18:06:32 -0400

The objective of the following script to to go thru a given Folder of Text files
and take each line containing text and make just one line of tabbed text 
(Which will later be inserted into an excel Spread Sheet). I have no problem with 
files containing Carriage returns or line feeds but have been unable to deal 
with files contain both. I have attached a folder containing one file with returns 
and one file containing returns and line feeds. 



set source_folder to choose folder
tell application "Finder"
set file_list to files in source_folder
end tell
repeat with this_file in file_list


set Title to this_file as text
set AppleScript's text item delimiters to "Macintosh HD:Users:thomas:Desktop:test folder:"
set Title1 to text item 2 of Title
set AppleScript's text item delimiters to ""
tell application "Microsoft Word"
open (this_file as alias)
set myDoc to active document
select myDoc
set Acctinfo to content of text object of selection
display dialog ">>>" & Acctinfo & "<<<"
close documents saving no


end tell
set {lf, retx} to {ASCII character 10, ASCII character 13}
set Multieol to false
if Acctinfo contains lf and Acctinfo contains retx then
display dialog "has both LF and retx"
set eol to lf & retx
set Multieol to true
else
if Acctinfo contains lf then
display dialog "has LF"
set eol to lf
else
if Acctinfo contains retx then
display dialog "has return"
set eol to retx
else
display dialog "Has neither"
end if
end if
end if
--if eol ≠ "Both" then
if not Multieol then
set AppleScript's text item delimiters to eol
set allines to Acctinfo's text items
set Numlnes to (count allines)
display dialog "Number of lines pre reduction=" & Numlnes
end if






--if eol = "Both" then
if Multieol then
display dialog "File " & Title1 & " Has Both CR LF"
set AppleScript's text item delimiters to eol
set lnefield to text items of Acctinfo
set AppleScript's text item delimiters to tab
set goodline to lnefield as string
display dialog "goodline=" & goodline
else
set Icount to 1
set goodline to Title1 & tab
set GoodFields to 0


repeat Numlnes - 1 times
set AppleScript's text item delimiters to eol
set lnefield to text item Icount of Acctinfo
if lnefield ≠ "" then
set goodline to goodline & lnefield & tab
set GoodFields to GoodFields + 1



end if


set Icount to Icount + 1






end repeat



display dialog "Number of Fields After reduction=" & GoodFields


display dialog "goodline=" & goodline
end if
end repeat

Attachment: test folder.zip
Description: Zip archive

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Delimit a File Containing Both Returns and Line Feeds
      • From: Deivy Petrescu <email@hidden>
  • Prev by Date: application dictionaries stop working
  • Next by Date: Re: Delimit a File Containing Both Returns and Line Feeds
  • Previous by thread: application dictionaries stop working
  • Next by thread: Re: Delimit a File Containing Both Returns and Line Feeds
  • Index(es):
    • Date
    • Thread