I have this file that gets the file names from a folder and saves as a text file.
I ned to copy the text into an Excel file and not to text file. Also getting rid of file extensions would be nice.
set sourceFile to (choose file with prompt "Choose Excel file" of type {"XLSX", "XLS", "TXT"} with multiple selections allowed without invisibles)
tell application "Microsoft Excel"
activate
open sourceFile
set wkbk_name to get full name of active workbook
set theRange to range "A2:A101" of sheet 1 of active workbook
set bold of font object of theRange to true
end tell
-- Create the text to be written to the file.
-- Just a heading and the item names, indented according to their positions in the hierarchy.
-- (Uncomment the (* *) comment markers to preserve the full paths.)
on createText(posixPaths)
script o
property paths : posixPaths
end script
set rootPath to beginning of o's paths
set item 1 of o's paths to "Entire contents of " & rootPath & linefeed
set astid to AppleScript's text item delimiters
-- (*
considering case
set AppleScript's text item delimiters to ""
set tabStr to {tab, tab, tab, tab, tab, tab, tab, tab, tab, tab, tab, tab, tab, tab, tab, tab, tab, tab, tab, tab} as text -- Hopefully more than needed!
set AppleScript's text item delimiters to "/"
set nonIndent to (count rootPath's text items) -- 1
set len to (count posixPaths)
repeat with i from 2 to len
set thisPath to item i of o's paths
set tiCount to (count thisPath's text items)
set thisName to text item -1 of thisPath
-- If the item name contains any colons, restore the original slashes.
if (thisName contains ":") then
set AppleScript's text item delimiters to ":"
set thisName to thisName's text items
set AppleScript's text item delimiters to "/"
set thisName to thisName as text
end if
-- If this is a folder path, append a colon to the name.
if ((i < len) and (item (i + 1) of o's paths begins with thisPath)) then set thisName to thisName & ":" -- or "/", if preferred.
-- set item i of o's paths to text 1 thru (tiCount - nonIndent) of tabStr & thisName
end repeat
-- *)
set AppleScript's text item delimiters to linefeed
set outText to o's paths as text
-- (*
set AppleScript's text item delimiters to linefeed & tab
set outText to outText's text items
set AppleScript's text item delimiters to linefeed
set outText to outText as text
end considering
-- *)
set AppleScript's text item delimiters to astid
return outText
end createText
-- Write the text to file as UTF-8.
on writeTextFile(txt, defaultLoc)
set f to (choose file name with prompt "Save the UTF-8 text listing as." default name (paragraph 1 of txt) & ".txt" default location defaultLoc)
set fRef to (open for access f with write permission)
try
set eof fRef to 0
write «data rdatEFBBBF» to fRef -- UTF-8 BOM.
write txt as «class utf8» to fRef
end try
close access fRef
display dialog "The listing has been saved in file \"" & f & "\"" buttons {"OK"} default button 1
end writeTextFile
on main()
set rootFolder to (choose folder with prompt "Choose a folder or disk to catalogue.")
-- List the hierarchy as POSIX paths, omitting any that contain elements beginning with ".".
set thePaths to paragraphs of (do shell script "find -f " & (quoted form of POSIX path of rootFolder) & " \\! -path \"*/.*\"")
set outText to createText(thePaths)
writeTextFile(outText, (path to documents folder))
end main
main()
Suggestions. I am searching through these forums.
Thanks in advance, Randy