rparsons
(Fresh Scripter)
2006-10-05 07:31 PM
Check file exists then copy

I need to copy a screen saver to the system32 dir of XP & 2000 systems and am trying o figure out how to check for it's existence first so it isn't copied over and over again.
Something like IF NOT EXIST (%sysemdir%\screen.scr) COPY "\\server\file" "%sytemdir%\file) END IF.

Can someone give me the right syntax for this? Thanks


Witto
(MM club member)
2006-10-05 08:07 PM
Re: Check file exists then copy

Check for extra information in the kix2010.doc
Code:

If NOT Exist("FileOrFolder")
Copy "Source" "Destination" /c /h
EndIf



NTDOCAdministrator
(KiX Master)
2006-10-05 09:33 PM
Re: Check file exists then copy

Would not recommend that code for Folder checking.

Also, unless the user has Admin rights they should not be able to copy that file into the system32 folder.

For a folder I'd use something like this. Though he did ask about a file.


If GetFileAttr('foldername') & 16
 


LonkeroAdministrator
(KiX Master Guru)
2006-10-05 10:36 PM
Re: Check file exists then copy

so, why do you offer folder then?

NTDOCAdministrator
(KiX Master)
2006-10-05 11:02 PM
Re: Check file exists then copy

Becasue Witto so suggested and I'm just pointing out what I think would be a better method.

Quote:

("FileOrFolder")




LonkeroAdministrator
(KiX Master Guru)
2006-10-05 11:17 PM
Re: Check file exists then copy

witto showed that you can use exist against both file and folder.
but didn't see such suggestion you are referring to.


Witto
(MM club member)
2006-10-05 11:46 PM
Re: Check file exists then copy

True, I (almost) copied the syntax from the kix2010.doc
I tried to show that quotes are missing, that brackets are misplaced and that EndIf is one word.
Just what was asked
Quote:


Can someone give me the right syntax for this?





NTDOCAdministrator
(KiX Master)
2006-10-06 01:24 AM
Re: Check file exists then copy

No problem Jooel or Witto. Was simply wanting to point out that it is possible to have a file with the name of a folder or the name of a folder with the name of a file and if that does exist the script will fail.

Witto's solution and explanation of why is valid. Just hoping to educate on a possible issue either now or in the future for new scripters.


Les
(KiX Master)
2006-10-06 02:16 AM
Re: Check file exists then copy

DOC, your logic is flawed. regardless of whether it is a file or folder that exists, if either exists the file should not be copied. In fact if there is a folder by the ssame name as the file, the copy would fail!

NTDOCAdministrator
(KiX Master)
2006-10-06 02:22 AM
Re: Check file exists then copy

Not sure how the logic could be flawed since I didn't provide any SILVER PLATTER code.

I only provided what I think would be a better TYPE of solution.

I could / would write some Silver Platter code if the original poster requests it though.


Les
(KiX Master)
2006-10-06 02:33 AM
Re: Check file exists then copy

Well my vote goes to Witto's code and I rise to his defense.

NTDOCAdministrator
(KiX Master)
2006-10-06 02:41 AM
Re: Check file exists then copy

That's cool. No problem, many ways to do the same task.

Most of us have the freedom to choose as well, which is good. Not trying to solicit some type of challenge.


rparsons
(Fresh Scripter)
2006-10-06 03:36 PM
Re: Check file exists then copy

Thanks. My syntax was based on m ow logic not true kixtart code but it's good to see I was close. Since I am using kixtart for our logon script (active directory), wouldn't the file copy to system32? I would think the script runs under admin context.

Björn
(Korg Regular)
2006-10-06 03:44 PM
Re: Check file exists then copy

The file will be copied to the path specified. Yes and no, the script runs under the user-context, if the user is a admin (why would an admin run a loginscript?...) then yes, runs as admin, if it's just a domain user, runs as a domain user etc.

rparsons
(Fresh Scripter)
2006-10-06 04:09 PM
Re: Check file exists then copy

Hmm. Good to know. I have the logic working now and the file is copying. Unfortunately I can see people putting on their on screen saver if its not in system32 or other denied folder (renaming their own). I could use SMS to do this and still may but is there a way to run it as admin?

Mart
(KiX Supporter)
2006-10-06 04:11 PM
Re: Check file exists then copy

Then you should schedule it as a scheduled task. This can even be done remotely.

Björn
(Korg Regular)
2006-10-06 04:17 PM
Re: Check file exists then copy

You can limit screensaver and background with a gpo if you wish.
What have I missed, why would you wanna schedule a filecopy?


rparsons
(Fresh Scripter)
2006-10-06 04:24 PM
Re: Check file exists then copy

Yea, I can limit the screen saver via GPO which I do but a person who knew enough could copy their own and rename it. The best I can think of is just make it read only and hidden in a common location like Program Files.

Björn
(Korg Regular)
2006-10-06 04:25 PM
Re: Check file exists then copy

or just change the permissions on the specified file not to include your users for change.

rparsons
(Fresh Scripter)
2006-10-06 04:36 PM
Re: Check file exists then copy

I thought about that but wouldn't the permission then get inherited by the receiving computer thereby replacing the permissions?

rparsons
(Fresh Scripter)
2006-10-06 04:38 PM
Re: Check file exists then copy

I just checked it and indeed, you get the inherited permissions. That's ok though. Thank everyone for your help. I learned a lot.