Newbie has a question

hello everybody,

for several days i’m working on a script and really don’t get forward with it.
here is my problem:

i have to files in a folder: xxxx.pdf and yyyy.job

i need a script which detects the xxxx.pdf in the given folder and replaces the yyyy with the xxxx. the suffixes have to stay the same!

can anybody help me?

Ok, let me make sure I understand what you’re doing. In a folder you have a .pdf file and .job file. You want to rename the .job file to the name of the .pdf file, both keeping their extensions(suffixes). Is this correct?

If I understood correctly, this can be done in the Finder. Something like this should work:


tell application "Finder"
	set myFolder to folder "path:to:the:folder:"
	tell myFolder
		repeat with i from 1 to count files
			if name extension of file i = "pdf" then
				set pdfFile to file i
			else if name extension of file i = "job" then
				set jobFile to file i
			end if
		end repeat
		set extension hidden of pdfFile to true
		set extension hidden of jobFile to true
		
		set pdfFileName to displayed name of pdfFile
		set name of jobFile to pdfFileName & ".job"
	end tell
end tell

it`s exactly what i mean. but still the .job file keeps the extension of the pdf-file.

this is what i get:

xxxx.pdf
xxxx.pdf.job

but thank you very much, maybe i can find out how to fix this problem.

and sorry for my english, it’s the next i have to work on

theflo

hello,

finally i found out, where the problem lies. on my g4 i have os x 10.3.4 and if i want to hide the extension of a file, it doesn´t work. so i tried my ibook and there with the same system installed i can hide the extension but i get an error that the variable of jobFile in the script is not declared.

does anybody know something about the problem with the extension on 10.3.4?

thanks

Try this:


tell application "Finder"
   set myFolder to folder "path:to:the:folder:"
   tell myFolder
      repeat with i from 1 to count files
         if name extension of file i = "pdf" then
            set pdfFile to file i
         else if name extension of file i = "job" then
            set jobFile to file i
         end if
      end repeat
      
      set pdfFileName to displayed name of pdfFile
      if (offset of ".pdf" in pdfFileName) is greater than 0
          set pdfFilename to (characters 1 thru ((offset of ".pdf" in pdfFileName) - 1) of pdfFileName) as string
      end if
      set name of jobFile to pdfFileName & ".job"
   end tell
end tell 

thanks, it’s exactly what i needed and it works fine! :smiley: