Jump to content

Compare Files


Guest blittle
 Share

Recommended Posts

Guest blittle

I need some newbie help. The scenario is, I have 2 files, one on a server and one in a temporary directory on my pc. I want to find out if the file that i have on my pc is in the server and if it is i want to delete it from the server. The catch is the file on the pc and server change periodically so i can't specify a file name in the script. I basically want to get the file name from the pc and pass it to the server and delete it if it is present. Any help would be much appreciated

B.

Link to comment
Share on other sites

You most likely want to do a file comparision or something, but here is a quick script to just do only what you said.

You can loop this if you like to do multiple files, I only used one, since you said file.

; Shows the filenames of all files in the current directory, note that "." and ".." are returned.
$search = FileFindFirstFile("c:\temp\*.au3"); change to whatever temp dir you have

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf
    $file = FileFindNextFile($search) 
    MsgBox(4096, "File:", $file)
; Close the search handle
FileClose($search)

If FileExists ("\\server\temp\"&$file) Then; change to your server location
; option 1
    $x=FileCopy("c:\temp\" & $file,"\\server\temp\" & $file,1) this will just overwrite it.
; option 2
;   $x=FileDelete("\\server\temp\"&$file); uncomment this if you meant to delete.
Else
MsgBox(1,"Info","File not on server.")  
$x=2
EndIf
If $x=1 Then MsgBox(1,"File deleted","")
If $x=0 Then MsgBox(1,"Error","File not deleted")

...edit added options.

Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...