Rename and Move the File to Server

Hi Everybody,

I am newbie to script, I need a script it may be a droplet or choose file type or Folder Action, what ever it may be I want to do the script should Rename the file and move to the Host/Local Server.

Please do let me know if anyone aware of this…hope you people may rocks!!!..

These are the steps I want to do:

  1. Choose file type are “PDF” and “HTML” it should be multiple files. (If it is great both should be Zipped after rename but its a optional).
  2. Then get the info from the user add after the underscore “_” in the original file name the extension remains same. (For eg. 10-1234-1_C10.1.pdf")
  3. Then the renamed file should moved to the Host Server.
  4. If the Host server is not exist, show the alert and connect automatically get the login info from user.
  5. At the same time one copy should be move to local server the original file should be deleted after moved.
  6. Before move to the Host server, match the folder name between Host and original source folder if both matches then the file should be moved.

I have wrote a code as attached but it not works fine.


tell application "Finder"
	
	choose file of type {"com.adobe.pdf"} with prompt "Choose the PDF"
	set theFiles to result
	set org to name of theFiles
	set source_folder to (name of theFiles) as string
	set file_path to (source_folder as string) as string
	set file_name to file_path as string
	set jobNumber to (characters 1 thru ((offset of "_" in file_name) - 1) of file_name) as text
	
	set dt to current date
	set m to month of dt as text
	set m to text 1 thru 3 of m
	set d to day of dt as text
	set y to year of dt as text
	set yr to text 3 thru 4 of y
	set mydate to (d & "-" & m & "-" & yr) as text
	
	
	
	set loginID to short user name of (system info)
	
	-- We have to enter manually the Drop Cycle number
	set cycle to display dialog "Enter the Cycle.Drop number (Only separated by Hyphen)" default answer "."
	set the drop to the text returned of the result as string
	
	
	-- Finder will change the file name
	tell application "Finder" to set name of theFiles to (jobNumber & "_" & "C" & drop & ".pdf")
end tell

set x to name of theFiles as text
display alert x buttons {"Quit", "Continue"} default button 2
if button returned of result is "Continue" then
	
	--To move the file with proper naming standard to the TRAINING server
	
	
	tell application "Finder"
		set mounted_Disks to list disks
		--display dialog result as string
		--set mounted_Disks to every disk whose (ejectable is true)
		
		if mounted_Disks does not contain "Training" then
			mount volume "afp://afp://xxxxxxxxxxxxxxxx/Training[b](Local Server[/b]" as user name "username" with password "password"
		end if
		
		try
			set Train to mount volume "afp://xxxxxxxxxxxxxxxx/Training[b](Local Server[/b])"
		end try
		
		set dt to current date
		set m to month of dt as text
		set w to text of m
		set m to text 1 thru 3 of m
		set d to day of dt as text
		set y to year of dt as text
		set mymonth to (w & " " & "Files") as text
		set mydate to (d & "-" & m & "-" & y) as text
		set myyear to y as text

		
		set sampleAudit to (("Training" as string) & "CHE" as alias)
		set create_month to ((((sampleAudit as string) & myyear as alias) & mymonth as alias))
		
		if (not (exists folder ((create_month as string) & (mydate as string)))) then
			make folder at create_month with properties {name:mydate}
			set mainFolder to ((Train as string) & "CHE" as alias)
			set create_month to ((mainFolder as string) & mymonth as alias)
			set targetFolder to ((create_month as string) & mydate as alias)
			move theFiles to targetFolder
			display alert "Copy of the file also moved in to the Training server"
			
		else
			set mainFolder to (("Training" as string) & "CHE" as alias)
			set create_month to ((mainFolder as string) & mymonth as alias)
			set targetFolder to ((create_month as string) & mydate as alias)
			
			move theFiles to targetFolder
			
			set ZZ to name of theFiles
			set YY to modification date of the files of targetFolder
			display alert "Copy of the file has been moved to the Local Training Server"
		end if
	end tell

	
	--To move the file with proper naming standard to the HOST Server
	
	try
		tell application "System Events"
			set UserName to name of current user
		end tell
	on error
		set UserName to display dialog "Please enter your User ID." with icon note default answer "" giving up after 15
		set UserName to text returned of UserName
	end try
	
	set mounted_Disks to list disks
	
	if mounted_Disks does not contain "Training" then
		
		try
			with timeout of 3600 seconds
				mount volume "afp://afp://xxxxxxxxxxxxxxxx/[b](HOST Server[/b]" as user name UserName
			end timeout
			
		on error
			set name of theFiles to org
			error "You have canceled login."
			
			--exit repeat
		end try
	end if
	
	try
		set TheServer to mount volume "aafp://xxxxxxxxxxxxxxxx/[b](HOST Server[/b]"
	end try
	
	
	set step1 to ((TheServer as string) & "CHE" as alias)
	set step2 to ((step1 as string) & "SUB Folder" as alias)
	set step3 to ((step2 as string) & "PERIODIC DATE" as alias)
	set destination to ((step2 as string) & loginID as alias)
	move theFiles to destination

	
	delete theFiles
	
else
	set name of theFiles to org
	
	display alert "Oops......your file name may be wrong please enter the correct Input again"
end if
--eject "ED_Transfer"

Hi,

I don’t already understand the first part of the script
The user chooses a file and then all variables are set to the name of the file.
Probably this is not intended.

You can create the date string more comfortable with a shell script line

set mydate to do shell script "/bin/date +%d-%b-%y"

I recommend to use the shell also to create the directories and move the file(s).
The mv command can move and rename at the same time

Hi Stefan,

Thanks for your quick response,

I need the script to do the following actions:

  1. I have a PDF and HTML files in the local server folder named with the Date for Eg. “3-26-2010”.

  2. The same folder name available in the Host Server also so, the script compare the folders if both matches moves all the files from local to the Host server also if the files already exist, do not replace and show alert.

  3. Also Create one folder in the same local server location called DONE, one copy the moved files to the DONE folders. It can easy to identify which files are moved to the Host Server. The local source folder become empty after all files moved.

This is what I want Stephen, hope you understand now what I expect. Please do the needful as early as possible.

Thanks in Advance!

Ganesh