Hi
I need to import in a File Maker Pro db the content of various files.
each file contains from 1 to 50 CR separated lines they all follow the very same structure.
I include one line as such where each line does not include spaces or any other symbol.
The Script should name the new text file with the first word in each paragraph as such
SCNSEQTAKE.txt
520101.txt
520102.txt
520202.txt
520201.txt
and include each paragraph.
Then move to the next file where the structure is exactly the same, until every file in the folder is done
I have more than 2000 files and doing it manually is practically imossible
Thanks and regards
Model: MACPRO
Browser: Safari 537.36
Operating System: Mac OS X (10.10.5)
The following script will read tab separated files from Filemaker. Note that Filemaker does not pad a space before and after the tab as the data you provide does. So, I did not account for any spaces before or after the tab in this solution.
To use: First, select the file(s) you wish to convert. You can pick multiple files in the choose file dialog by holding down the command key and selecting the files. Second, select the folder where you want the converted file to be saved.
set tabFiles to (choose file with prompt "Select tab file..." of type {"txt"} with multiple selections allowed)
set saveFolder to (choose folder with prompt "Select folder to save results to:") as text
repeat with aFile in tabFiles
set tabFile to aFile as text
set tabRecords to read file tabFile using delimiter {return}
set theData to tabRecords as text
set fileName to (word 1 of first item of tabRecords) & ".txt" as text
set theFile to saveFolder & fileName as text
try
set dataOut to open for access file theFile with write permission
set eof of dataOut to 0
write theData to dataOut starting at eof
close access dataOut
on error
try
close access file theFile
end try
end try
end repeat
on getItems(theRecord)
copy the text item delimiters to origDelims
set the text item delimiters to tab
set recordItems to {}
set recordItems to every text item of theRecord
set the text item delimiters to origDelims
return recordItems
end getItems
Browser: Firefox 50.0
Operating System: Mac OS X (10.10)