Copying a list of files to a new folder - csv

I have a list of image filenames (csv file) and I want to check if these images exist in a folder of images. If the image exists I want to copy it over to new folder.
I built a sample code that runs through without error and duplicated the first matching file to the destination folder correctly. However the rest of the files it returns that it doesn't find a match although they are clearly present in the source folder. Any ideas what is going wrong?
--Step 1. Get file path and read file.
set csvFile to (choose file with prompt "Select CSV file...") as text
set csvRecords to read file csvFile using delimiter {return}
set sourceFolder to (path to documents folder as text) & "AllProducts:"
set destinationFolder to (path to documents folder as text) & "SelectedProducts:"
--Step 2. Process each record (data row) by first extracting the record data as text items.
repeat with thisRecord in csvRecords
set recordItems to my getItems(thisRecord)
-- Enter processing code here
set filePath to sourceFolder & thisRecord
log filePath
tell application "Finder"
if (exists file filePath) then
duplicate file filePath to folder destinationFolder
else
log "File doesn't exist" & thisRecord
end if
end tell
end repeat
--Subroutine that returns the text items from each record.
on getItems(theRecord)
copy the text item delimiters to origDelims
set the text item delimiters to ","
set recordItems to {}
set recordItems to every text item of theRecord
set the text item delimiters to origDelims
return recordItems
end getItems

Related

How to read and write to the same csv file using lotusscript?

I have a CSV file. I need to read each line from this file, perform certain function and once done, I need to append a value something like "updated" at the end of each line. Can someone help me to achieve this using LotusScript ? I am using "open file for input" statement to open and read the file. I want to append the value after the function is performed at each line.
Open xlFilename$ For Input As Filenum%
Do Until Eof(Filenum%)
Line Input #Filenum%, txt$
'perform certain function
**'Would like to append csv here.**
loop
close Filenum
If you were appending new rows at the end, you would need to close the file, and then Open it again to append. I.e., after your loop...
Close Filenum
Open xlFilename$ For Append As Filenum2
Print #Filenum2, stuffYouWantToAppend
But I see you are trying to append new columns at the end of each row. It's going to be much easier if you simply treat your existing file as input and create a new one that you will Print to for output.
Open xlFilename$ For Input As Filenum1%
Open xlFilename$ + ".output.csv" For Output As Filenum2%
Do Until Eof(Filenum%)
Line Input #Filenum1%, txt$
'perform certain function
Print #Filenum2%, txt + "," + additionalColumnsGoHere
loop
close Filenum
And if you want, you could then Kill your input file and then rename your output file back to the original file's name using the Name statement.
Doing it in place is probably possible by opening the file in RANDOM READ WRITE mode, but it just isn't worth the trouble.

Access - TransferText acExportDelim Exported File Location and Name Not Correct

I'm having a problem with DoCmd.TransferText acExportDelim where it will export the desired file from my query, but it will not format the outputted file name as expected and it places the file one folder up in the selected folder path.
I do the entire export operation via a form. The user selects the folder path in the form, then the query ID, and the VBA code appends them together in the "FileName" parameter of DoCmd.TransferText acExportDelim like so:
DoCmd.TransferText acExportDelim, "Export Specification", "QueryName", "Me.FileLocationTextField.Value Me.QueryIDComboBox.Value .csv", TRUE
The above code will output the file from the query, but it will have a file name like "Me#FileLocationTextField#Value Me#QueryIDComboBox#Value". The file has the correct contents, it's just that the name is not the text that is stored in the Query ID Combo Box, which is what I would prefer.
The other issue is that the File Location is always one folder up in the folder path. So if the user selects "C:\Users\User\Documents\Exported Files\CSV Files" the file will be exported to "C:\Users\User\Documents\Exported Files".
I've tried setting the confirming the value of Me.FileLocationTextField.Value with a MsgBox and it is indeed showing the correct and full path before it is sent to TransferText acExportDelim. I've also tried several combinations of escape characters and concatenations for the FileName parameter but none have worked to get the file name or the folder path to work correctly.

Applescript - Duplicate Folder then rename & rename files inside

I'm trying to create a script that copies a template folder to current finder window then renames the new folder and a couple of files within it based on dialogue input.
So far, I've got it so it can copy a folder (from a selection) to the current finder window and rename it. But I can't get it to then rename a file within it.
Here's the code -
property A : POSIX file "/BLOCKED OUT FOR PRIVACY/" as alias
property B : POSIX file "/BLOCKED OUT FOR PRIVACY/" as alias
property C : POSIX file "/BLOCKED OUT FOR PRIVACY/" as alias
property D : POSIX file "/BLOCKED OUT FOR PRIVACY/" as alias
tell application "Finder"
set x to target of window 1 as alias
end tell
set JobName to text returned of (display dialog "Enter Folder Name:" default answer "Template Folder")
set CATno to text returned of (display dialog "Enter CAT number:" default answer "CMXX0000")
set optionList to {"OPTION 1", "OPTION 2", "OPTION 3", "OPTION 4"}
set chosenFolder to choose from list optionList with prompt "Choose a Folder"
set chosenFolder to chosenFolder's item 1
if chosenFolder is "OPTION 1" then
tell application "Finder"
set FolderCopy to duplicate B to x
set the name of FolderCopy to JobName
set Insert to (POSIX path of (path to home folder)) & "DVD Insert Artwork/Indesign Project File/_Insert.indd" as POSIX file
set the name of Insert to JobName & CATno
end tell
end if
I've cut out the POSIX file paths as they contain my company name and such. I've also left out the other parts of the if as they'll essentially be duplicates of the first.
set Insert to (POSIX path of (path to home folder)) & "DVD Insert Artwork/Indesign Project File/_Insert.indd" as POSIX file
set the name of Insert to JobName & CATno
This is the part that's giving me trouble. It should be renaming a file that is within the newly duplicated folder to the what's entered in the CATno dialog box + "_Insert.indd"
Any help is greatly appreciated!
Thanks :)
I'm not sure but do you mean this?
tell application "Finder"
set FolderCopy to duplicate B to x
set insertFile to file "_Insert.indd" of FolderCopy
set the name of FolderCopy to JobName
set name of insertFile to (JobName & CATno & "_Insert.indd")
end tell
The gets the reference to the indesign file from the duplicated folder.

Browse to file removing link cell in SQL

We have unique records created via a webpage and this has a browse for file to upload a image specific to this record. When the file is saved the URL location of the file is saved in SQL for that record to be recalled later in the system.
When you edit this record in the webpage and do not select a file, the SQL cell is made null.
here is the save code:
ByVal ID As HttpPostedFileBase
Dim folderPath As String = ""
If ID IsNot Nothing Then
folderPath = Server.MapPath("~/Content/ID/")
If Not Directory.Exists(folderPath) Then
Directory.CreateDirectory(folderPath)
End If
ID.SaveAs(folderPath & Record.UniqueID & ID.FileName)
Record.ID= "/Content/ID/" & Record.UniqueID & ID.FileName
End If
When the Browse for file is 'No File Chosen' it will overwrite the Record.ID making it null. do i need to add a text field to pull SQL URL through to stop the overwriting by checking if that is null?

Applescript - bulk convert PPT to HTML

My knowledge of coding is limited. I am trying to automate a process of converting PPTs to HTML using applescript and Keynote. In this page I found the following non working apple script:
-- THE DESTINATION FOLDER
-- (see the "path" to command in the Standard Additions dictionary for other locations, such as pictures folder, movies folder, sites folder, desktop folder)
set the defaultDestinationFolder to (path to documents folder)
tell application "Keynote"
activate
try
if playing is true then tell the front document to stop
if not (exists document 1) then error number -128
-- DERIVE NAME FOR NEW FOLDER FROM NAME OF THE FRONT DOCUMENT
set documentName to the name of the front document
if documentName ends with ".key" then ¬
set documentName to text 1 thru -5 of documentName
-- CREATE AN EXPORT DESTINATION FOLDER
-- IMPORTANT: IT’S ADVISED TO ALWAYS CREATE A NEW DESTINATION FOLDER, AS THE CONTENTS OF ANY TARGETED FOLDER WILL BE OVERWRITTEN
tell application "Finder"
set newFolderName to documentName
set incrementIndex to 1
repeat until not (exists folder newFolderName of defaultDestinationFolder)
set newFolderName to documentName & "-" & (incrementIndex as string)
set incrementIndex to incrementIndex + 1
end repeat
set the targetFolder to ¬
make new folder at defaultDestinationFolder with properties ¬
{name:newFolderName}
set the targetFolderHFSPath to targetFolder as string
end tell
-- EXPORT THE DOCUMENT
with timeout of 1200 seconds
export front document as HTML to file targetFolderHFSPath
end timeout
on error errorMessage number errorNumber
display alert "EXPORT PROBLEM" message errorMessage
error number -128
end try
end tell
-- OPEN THE DESTINATION FOLDER
tell application "Finder"
open the targetFolder
end tell
-- VIEW THE PRESENTATION
tell application "Safari"
activate
open file (targetFolderHFSPath & "index.html")
end tell
I am looking for a way to fix this. Currently I am getting the following result:
error "Keynote got an error: No user interaction allowed." number -1713
You've broken one of the basic rules of applescript. Avoid putting tell blocks inside tell blocks. In your case you put a Finder tell block of code inside the Keynote tell block of code. This could cause conflicts and thus errors. I think that's your problem.
Try this with the tell blocks separated...
-- THE DESTINATION FOLDER
-- (see the "path" to command in the Standard Additions dictionary for other locations, such as pictures folder, movies folder, sites folder, desktop folder)
set the defaultDestinationFolder to (path to documents folder)
try
tell application "Keynote"
activate
if playing is true then tell the front document to stop
if not (exists document 1) then error number -128
-- DERIVE NAME FOR NEW FOLDER FROM NAME OF THE FRONT DOCUMENT
set documentName to the name of the front document
if documentName ends with ".key" then ¬
set documentName to text 1 thru -5 of documentName
-- CREATE AN EXPORT DESTINATION FOLDER
-- IMPORTANT: IT’S ADVISED TO ALWAYS CREATE A NEW DESTINATION FOLDER, AS THE CONTENTS OF ANY TARGETED FOLDER WILL BE OVERWRITTEN
end tell
tell application "Finder"
set newFolderName to documentName
set incrementIndex to 1
repeat until not (exists folder newFolderName of defaultDestinationFolder)
set newFolderName to documentName & "-" & (incrementIndex as string)
set incrementIndex to incrementIndex + 1
end repeat
set the targetFolder to ¬
make new folder at defaultDestinationFolder with properties ¬
{name:newFolderName}
set the targetFolderHFSPath to targetFolder as string
end tell
-- EXPORT THE DOCUMENT
with timeout of 1200 seconds
tell application "Keynote"
export front document as HTML to file targetFolderHFSPath
end tell
end timeout
on error errorMessage number errorNumber
display alert "EXPORT PROBLEM" message errorMessage
error number -128
end try
-- OPEN THE DESTINATION FOLDER
tell application "Finder"
open the targetFolder
end tell
-- VIEW THE PRESENTATION
tell application "Safari"
activate
open file (targetFolderHFSPath & "index.html")
end tell