jszei
(Fresh Scripter)
2005-12-13 10:56 PM
If Exist Ren & Copy

Hey guys,

I am trying to rename a file on a PC if it exists then copy a file from a server to a PC as a new name. Here's what I've got but the syntax is wrong. Can anyone help?
Code:
  


Dim $mapir
$mapir="C:\Program Files\Common Files\System\Msmapi\1033"
If Exist $mapir +"\"mapir.dll
REN $mapir +"\"mapir.dll $mapir"\"mapir.old
COPY "\\mnc17p1s\NETLOGON\batch\mapirnew.dll" $mapir +"\" mapir.dll
End If
Code:
  



Thanks & try to hold back the laughs,
John


StarwarsKid
(Seasoned Scripter)
2005-12-13 11:55 PM
Re: If Exist Ren & Copy

Looks like you'll want to use the MOVE command instead of REN. Also, ENDIF is one word in KiXtart.

Look in the Manual for more info on "MOVE".

Code:


Dim $mapir
$mapir="C:\Program Files\Common Files\System\Msmapi\1033\"

If Exist $mapir + "mapir.dll"
MOVE $mapir + "mapir.dll" $mapir + "mapir.old" /h /s
COPY "\\mnc17p1s\NETLOGON\batch\mapirnew.dll" $mapir + "mapir.dll"
EndIf



Les
(KiX Master)
2005-12-13 11:59 PM
Re: If Exist Ren & Copy

Where did you get REN from? Not the manual, I'm sure. You cannot be making up your own commands but you could create your own UDF.

Les
(KiX Master)
2005-12-14 12:01 AM
Re: If Exist Ren & Copy

Oh, and your VBer roots are showing... it's EndIf, not End If.

jszei
(Fresh Scripter)
2005-12-14 12:11 AM
Re: If Exist Ren & Copy

I ran your script through the editor & it doesn't work.
It dies here: If Exist $mapir + "mapir.dll" with invalid method/function call.
I thought the move command to rename was strictly Unix. It works within Kix for Windows as well? Yes, yes Microsoft has be by the collar.

Thanks,
John


Les
(KiX Master)
2005-12-14 12:16 AM
Re: If Exist Ren & Copy

Do you have a manual?
If so, look up the Exist() function!


StarwarsKid
(Seasoned Scripter)
2005-12-14 12:17 AM
Re: If Exist Ren & Copy

Yes. Read the manual that comes with KiXtart(or at least search it for the function you're trying to perform). You will find a list of functions and their use and syntax. Sorry, I didn't test the code, just cleaned up your original code to the best of my ability.

My EXIST syntax was wrong.

After Reading the manual I found that the syntax is correct as follows:

Code:
 
If Exist ($mapir + "mapir.dll")




jszei
(Fresh Scripter)
2005-12-14 12:39 AM
Re: If Exist Ren & Copy

The corrected EXIST syntax works, thank you. You don't have to apologize, it's not like I could ever get upset at anyone for helping me. I do appreciate it and as this is the Starter's BB I would hope to be treated as a someone with very little knowledge *bows down to the greatness above*
Next in my debug I am getting Unknown or Unexpected Command Move.
Can't seem to find anything in the manual


Les
(KiX Master)
2005-12-14 12:41 AM
Re: If Exist Ren & Copy

What version @KiX ?

jszei
(Fresh Scripter)
2005-12-14 12:43 AM
Re: If Exist Ren & Copy

4.12

Les
(KiX Master)
2005-12-14 12:47 AM
Re: If Exist Ren & Copy

Starters forum or not... is no excuse not to read the manual!
Quote:

Fixes/enhancements in 4.20:
- Enhanced tokenizing engine

- Join() now takes a 3rd parameter: the number of elements of the array to join

- Added AScan()

- Added IIf()

- Added recursion ('/s') to COPY and DEL

- Added MOVE command (to move and/or rename files or directories)





jszei
(Fresh Scripter)
2005-12-14 12:58 AM
Re: If Exist Ren & Copy

Moderator or not Les your tone sucks. Not just in this post but others I have read. Not all of us are as brilliant as you Les. I tried to show gratitude for the help given and all you seemed to do was stick your finger up at me. You should take notes from NTDOC, he is extremely polite, helpful and NOT CONDESCENDING. Take your bad day or life out on someone else.

Les
(KiX Master)
2005-12-14 01:23 AM
Re: If Exist Ren & Copy

Hey, I'm not having a bad day...

When SWK suggested you "Look in the Manual for more info on "MOVE"", had you said then that it was not in your manual, we would not have to wonder what version you are running.

Now, when you say "Can't seem to find anything in the manual", one needs to wonder what you really mean because I can find lots of good things in there, albeit in the 4.12 version, nothing on MOVE.


LonkeroAdministrator
(KiX Master Guru)
2005-12-14 06:48 AM
Re: If Exist Ren & Copy

lol.
oh, btw, the 4.51 chm is now downloadable from kixtart.org/manual


jszei
(Fresh Scripter)
2005-12-14 04:00 PM
Re: If Exist Ren & Copy

Must be a bad life then. That would make sense since all your posts have that same, short "look somewhere else, why are you asking me" answer. Why do you think we're posting here. If you think you're educating don't become a teacher. If you have nothing to say but RTFM then don't reply to the posts. I hope someone makes you feel stupid for asking something you don't know, and I'm sure there is a lot you don't know. Oh, and thanks for the help.

Les
(KiX Master)
2005-12-14 07:41 PM
Re: If Exist Ren & Copy

I really don't know what your problem is. There is no detail in your profile that would lead me to believe that perhaps English is a second language or that there is some cultural sensitivity, so I must assume it is just a bad attitude.

I realize that beginners need to start somewhere and IMHO what better place to start than with the manual. I don't know how you expect to earn respect when you flagrantly ignore the manual with its fine examples and then ignore the good advice offered on this board.

I think you should reflect back upon your own work and think about what a supervisor would think of someone that just makes up commands and syntax that do not exist in the manual. By not doing proper research and simply posting to the board, you are likely to get the advice du jour from whoever happens to answer your post which may not prove to be the best advice in the end.

I recognize that I have a low tolerance for mediocrity but see nothing before this post that should illicit such a response from you.


jszei
(Fresh Scripter)
2005-12-14 08:51 PM
Re: If Exist Ren & Copy

Couldn't resist a retort could you. Now you are revealing yourself as a racist with your reference to English as a second language. Who are you to knock anyone who might actually be able to speak two languages where English is the second. Your quip was not funny. Especially being from Canada where you can't decide which language is your own. My problem has been your response to my post from the beginning. It's rude. The only bad advice I got was from you. SWK offered good advice.
Les says "I recognize that I have a low tolerance for mediocrity". Recognition is the first step. Next take a look at your own life and realize how you can not tolerate yourself. Your arrogance is appaling. Please don't respond to my post anymore, I am tired of your less than mediocre dialogue.


Mart
(KiX Supporter)
2005-12-14 09:03 PM
Re: If Exist Ren & Copy

Wow, calm down you guys. I'm sure nobody here is a true racist so there is no need calling people names like that. Some people might have a way of replying that could look like an insult but is not meant like that. I've had some good help out of les's replies in the past.

Let’s stop calling each other names and continue nice and polite please. We just had some threads here where this also came up and I hoped we put it to sleep and everybody was being nice again, guess not. If you take offence to a reply someone gave then be the stronger one and just ignore it. Please stop the name calling.



ShawnAdministrator
(KiX Supporter)
2005-12-14 10:44 PM
Re: If Exist Ren & Copy

Les said:
Quote:


I recognize that I have a low tolerance for mediocrity but see nothing before this post that should illicit such a response from you.





As an outside observer - I agree with Les's statement. jszei your taking these comments wrong (and way too personally). I can tell by your writing that your no dumby either. I've known Les for years now - can assure you that A) he's no racist and B) he knows what he's talking about. He just has a low tolerance for people asking questions about stuff thats clearly in the manual - thats all ;0)


jszei
(Fresh Scripter)
2005-12-14 10:51 PM
Re: If Exist Ren & Copy

My apologies Les. With all these people backing you up you must be a stand up guy. It just happens that my wife's native language is not english and is taking ESL courses. You struck a nerve.

If anyone is still willing to help me out after this my code is not renaming the file properly after updating Kix to 4.51.
Code:

Dim $mapir
$mapir="C:\Program Files\Common Files\System\MSMAPI\1033\"
If Exist ($mapir + "mapir.dll")
MOVE $mapir + "mapir.dll" $mapir + "mapir.old" /h /s
COPY "\\mnc17p1s\NETLOGON\batch\mapirnew.dll" $mapir + "mapir.dll"
EndIf



Thanks


LonkeroAdministrator
(KiX Master Guru)
2005-12-14 11:03 PM
Re: If Exist Ren & Copy

add this line after your move if it's failing:
@error " - " @serror ?


StarwarsKid
(Seasoned Scripter)
2005-12-14 11:21 PM
Re: If Exist Ren & Copy

Hello Jszei (Hungarian name by chance???),

It is a fairly simple process to change out the existing KiXtart files for your existing version. In fact, all that needs done is either you replace the current kixtart.exe with the new one or change your BATch file execution or User profile path to the new location. Of course, you should test out all your KiXtart scripts in the new version before commiting the change to the production environment.

I understand your frustration. It's hard to know where to look for the answers some times. For the most part, the manual will have all the KiXtart commands listed with a basic explanation of its use and some syntax questions. If you need to do something, but don't know how to in KiXtart, just post some "pseudo code" (plain english) and we'll try to help you build a KiXtart framework.

In my experience the learning curve is STEEP, especially for a non-programmer like myself. There are a lot of helpful people on this board. I hope you continue posting your questions. They're great for the community!!

P.S. (oops, looks like I replied a few posts before the end of the thread. I missed some later comments.... Tee hee)

By the way, the @error command will return an error code (usually a number) that will help define why the script is having problems at that line.

P.S.S By the way, verify the spelling of ALL files and directories, just to be absolutely confident that isn't the problem.


StarwarsKid
(Seasoned Scripter)
2005-12-14 11:37 PM
Re: If Exist Ren & Copy

Also, if you're having problems with the MOVE command it looks like Jooel wrote a UDF to do this.

"Rename UDF" http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=83392&an=0&page=15#83392

Do you know how to use UDFs?


NTDOCAdministrator
(KiX Master)
2005-12-15 12:24 AM
Re: If Exist Ren & Copy

This code should work fine for you (it should show you if there was an error changing the file - NOTE this will run everytime unless you change the code somehow to prevent it.)

Why not just check the version of the file and only copy it if it's the wrong version ?


Break On
Dim $Source
$Source = ExpandEnvironmentVars(ReadValue('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion','ProgramFilesPath'))
If Exist($Source +'\Common Files\System\MSMAPI\1033\MAPIR.DLL')
Move $Source +'\Common Files\System\MSMAPI\1033\MAPIR.DLL' $Source +'\Common Files\System\MSMAPI\1033\MAPIR.OLD'
'Moving file: ' + @ERROR + ' ' + @SERROR ?
Copy '\\mnc17p1s\NETLOGON\batch\mapirnew.dll' $Source +'\Common Files\System\MSMAPI\1033\MAPIR.DLL'
'Copying new file: ' + @ERROR + ' ' + @SERROR ?
EndIf

 


LonkeroAdministrator
(KiX Master Guru)
2005-12-15 12:07 PM
Re: If Exist Ren & Copy

SWK,
iirc, I wrote the UDF when there was no move in kixtart.
as I still think, he might have file name or path incorrect, and thus he should try the error line to see why it's failing.

obviously, if you want to show gui, you can go with my rename UDF


jszei
(Fresh Scripter)
2005-12-15 05:49 PM
Re: If Exist Ren & Copy

NTDOC you've come through again. Why do you think my code didn't work? I added the error line which didn't report anything and I run the code through a debugger which didn't report anything.
I ended up adding a goto statement if there already is a mapir.old file. I'm not sure how to have it check the version. I'll look through the manual to see if it tells how to do that.

Code:
 Dim $Source
$Source = ExpandEnvironmentVars(ReadValue('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion','ProgramFilesPath'))
If Exist($Source +'\Common Files\System\MSMAPI\1033\MAPIR.OLD')
GOTO "reg"
Else
If Exist($Source +'\Common Files\System\MSMAPI\1033\MAPIR.DLL')
Move $Source +'\Common Files\System\MSMAPI\1033\MAPIR.DLL' $Source +'\Common Files\System\MSMAPI\1033\MAPIR.OLD'
Copy '\\mnc17p1s\NETLOGON\batch\mapirnew.dll' $Source +'\Common Files\System\MSMAPI\1033\MAPIR.DLL'
EndIf



SWK, nope not Hungarian. I'm an American mutt. The name is either Dutch or German and we're not sure if it's shortened or not. Some controversy lingers. Thank you for all your help. The positive words encourage me to learn more.

John


LonkeroAdministrator
(KiX Master Guru)
2005-12-15 06:45 PM
Re: If Exist Ren & Copy

hmm...
sorry, added the errorline and it did not report anything is a false statement.
it will report even success.
you can't have such line without it reporting something.

or, you are not running the script via kixtart...


Les
(KiX Master)
2005-12-15 07:55 PM
Re: If Exist Ren & Copy

GOTOs are bad. Every IF needs a corresponding EndIf.

StarwarsKid
(Seasoned Scripter)
2005-12-15 08:03 PM
Re: If Exist Ren & Copy

Use this syntax to check file times

Code:
 
$Result = CompareFileTimes("\\someserver\somefolder\somefile", "C:\somefolder\somefile")
IF $Result = 1 or $Result = -3 ; '1'=File1 is more recent than file2, '-3'=File2 couldn't be open (nonexistant)
;do something
ENDIF



For file versions use GETFILEVERSION ("file name","versionfield")
(page 76-77 in KiXtart 4.50 Manual)
Syntax:
Code:
 $Result = GetFileVersion(@LDRIVE + "\Kix32.exe")

$Result = GetFileVersion(@LDRIVE + "\Kix32.exe", "ProductVersion" )



jszei
(Fresh Scripter)
2005-12-15 11:09 PM
Re: If Exist Ren & Copy

Jooel, It's really not reporting anything. I've looked for something in the eventlog, I have no kixtart.log file and no Dr. Watson pops up. I run the script through kixstarter v3.28 as well as the command line with /d and it doesn't report anything. I'm probably missing something but I don't know what.

Why are goto's bad? What other options do I have if I want to stop it from renaming mapir.dll everytime?
Do I just add another endif to the end?
endif
endif

You said it SWK, steep learning curve.


NTDOCAdministrator
(KiX Master)
2005-12-15 11:13 PM
Re: If Exist Ren & Copy

By checking the version you can decide if you want to copy / move it or not.

See post above and look in the manual. If you still need assitance with that let us know and we'll show you.

GOTO is difficult to debug and track down problems and can have scope issues. Some things which you may not understand right now, but take our word for it you'll be much better off in the long run if you stay away from the GOTO.

 


Les
(KiX Master)
2005-12-16 12:15 AM
Re: If Exist Ren & Copy

Basically, the way you coded it, the GOTO is not really needed. I havent bothered to analyze how KiX would process your code with the missing endif but if the second required EndIf were there, this is how it would look.
Code:
Dim $Source
$Source = ExpandEnvironmentVars(ReadValue('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion','ProgramFilesPath'))
If Exist($Source +'\Common Files\System\MSMAPI\1033\MAPIR.OLD')
;do nothing
Else
If Exist($Source +'\Common Files\System\MSMAPI\1033\MAPIR.DLL')
Move $Source +'\Common Files\System\MSMAPI\1033\MAPIR.DLL' $Source +'\Common Files\System\MSMAPI\1033\MAPIR.OLD'
Copy '\\mnc17p1s\NETLOGON\batch\mapirnew.dll' $Source +'\Common Files\System\MSMAPI\1033\MAPIR.DLL'
EndIf
EndIf


Using the compare on the two files would cause the script to access the network share. OK if there is a chance the network version will be updated again but if this is a one time thing, you could just check the local version and string compare it.
Code:
If GetFileVersion($Source +'\Common Files\System\MSMAPI\1033\MAPIR.DLL', 'ProductVersion') <> 'whateveritssupposedtobe'
;do whatever
EndIf



LonkeroAdministrator
(KiX Master Guru)
2005-12-16 01:24 AM
Re: If Exist Ren & Copy

jscei,
lets take a crash course in kixtart.
create a text file in notepad.
place only the error line in it:
@error " - " @serror ?

and then save the file, with what ever name you wish.
then go to the folder your kixtart executable resides, and execute it:
kix32 myscriptpath\myscriptFile.txt

the output is:
0 - Operation completed successfully.

and, that's what it reports.
every time you run kixtart script and you have the errorline there, it will give you output.
if you can't see it, the part of the script where your errorline is, isn't running at all, or you are not watching.


jszei
(Fresh Scripter)
2005-12-19 11:40 PM
Re: If Exist Ren & Copy

Well that was a good lesson Jooel. The Kixstarter program didn't show the error and whatever I did before with the command line was wrong because I got an error code return. The problem was in the path. there was a \ at the end and it couldn't find the path specified.

Les and NTDOC thank you for your help I will be educating myself from this post for a while.


jszei
(Fresh Scripter)
2005-12-22 05:06 PM
Re: If Exist Ren & Copy

Well, I've run into another issue. It seems that the file can not be renamed by the standard Windows user account. Is there a way to call the admin account to perform this action?

Thanks


LonkeroAdministrator
(KiX Master Guru)
2005-12-22 05:37 PM
Re: If Exist Ren & Copy

yes and no.
you can use something like runAs but surely you know that giving the admin account visible to normal user account makes your system vulnerable.

anyways, if you wish to go with runAs, search the board for examples.


LonkeroAdministrator
(KiX Master Guru)
2005-12-22 05:39 PM
Re: If Exist Ren & Copy

oh and best thing would be to make a admin script that scans all the wksta's and does the change.