how to copy and rename a file without changing the extension
Posted: Sat Sep 27, 2014 3:40 pm
Hi, being busy with my next problem.
i have read some tutorials and also working with files. but i can't figure it out. you can also see in my script piece that i tried some possiblities.
Want i want is to open a file, copy it to an other destination and rename it depending on a field input and without changing the extension of the file.
I saw a few examples but nowhere was thought about the extension (at least as far as i could see).
Then if this is working i want to alter it so that only pdf or jpg can be copied.
First i ask for the file, and set it in a local or global (both are not giving me want i want but ok):
I just changed this in the above code:
So the piece of which extension to load is solved 
Then trying to copy it and rename it, but although it does not give an error, it does not copy and rename it:
I hope that someone has a clue and can tell me what i do wrong..
Thanks for any help on this.
i have read some tutorials and also working with files. but i can't figure it out. you can also see in my script piece that i tried some possiblities.
Want i want is to open a file, copy it to an other destination and rename it depending on a field input and without changing the extension of the file.
I saw a few examples but nowhere was thought about the extension (at least as far as i could see).
Then if this is working i want to alter it so that only pdf or jpg can be copied.
First i ask for the file, and set it in a local or global (both are not giving me want i want but ok):
Code: Select all
on mouseUp
# Start by getting the file to upload
global gFileForUpload
answer file "Select a file to upload"
put it into gFileForUpload
#put tFileForUpload into specialFolderPath("Documents")
#revCopyFile url ("binfile:" & slash & tFileForUpload) , ("binfile:" & specialFolderPath("Documents") & slash)
end mouseUp
Code: Select all
answer file "Select a file to upload" with type "PDF document|pdf|PDF" or type "JPG document|jpg|JPG"

Then trying to copy it and rename it, but although it does not give an error, it does not copy and rename it:
Code: Select all
on mouseUp
# copy and Rename file
#put gFileForUpload into url ( "file:"& specialFolderPath("Documents") # & slash & field "new name")
put field "new name" into tDestFile
open file gFileForUpload
open file tDestFile
write gFileForUpload to file tDestFile
end mouseUp
I hope that someone has a clue and can tell me what i do wrong..
Thanks for any help on this.