Nova Posted June 8, 2004 Share Posted June 8, 2004 Hi guys Ive just come out of batch file writing but batch file programming powerfull as it is has some key features missing that I have found in autoitv3 I have a command here from batch and im hoping that someone can help me turn it into a autoit v3 command. IF EXIST %0 (copy %0 c:\newfolder\) ELSE (copy %0.bat c:\newfolder\) The above code will copy the excuted batch file to c:\newfolder Can anyone show me how this can be done in autoit ??? Tnx in advance Nova Link to comment Share on other sites More sharing options...
SlimShady Posted June 8, 2004 Share Posted June 8, 2004 Here it is: If FileExists(@ScriptFullPath) Then FileCopy(@ScriptFullPath, "c:\newfolder\*.*") Else FileCopy(@ScriptFullPath, "c:\newfolder\*.*") EndIf Link to comment Share on other sites More sharing options...
Developers Jos Posted June 8, 2004 Developers Share Posted June 8, 2004 IF EXIST %0 (copy %0 c:\newfolder\) ELSE (copy %0.bat c:\newfolder\)If $CMDLINE[0] = 1 Then If FileExists($CMDLINE[1]) Then FileCopy($CMDLINE[1], "c:\newfolder\*.*", 1) ElseIf FileExists($CMDLINE[1] & ".bat") Then FileCopy($CMDLINE[1] & ".bat", "c:\newfolder\*.*", 1) Else MsgBox(0, 'File not found', 'File not found:' & $CMDLINE[1]) EndIf Else MsgBox(0, 'No parameter', 'No parameter specified') EndIf SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Valik Posted June 8, 2004 Share Posted June 8, 2004 Here it is: If FileExists(@ScriptFullPath) Then FileCopy(@ScriptFullPath, "c:\newfolder\*.*") Else FileCopy(@ScriptFullPath, "c:\newfolder\*.*") EndIfWhy check to see if the exists? Unlike a batch file, it's not possible for the script that's running to be deleted (while it is running), so you can safely just use: FileCopy(@ScriptFullPath, "c:\newfolder\*.*") Link to comment Share on other sites More sharing options...
SlimShady Posted June 8, 2004 Share Posted June 8, 2004 Yeah... He wanted help with Converting Batch Command ----> Autoitv3So I translated it litterally. Link to comment Share on other sites More sharing options...
Nova Posted June 8, 2004 Author Share Posted June 8, 2004 (edited) Tnx guys that worked pretty well. That makes the file copy itself to c:/newfolder as I asked But if the code is changed to If FileExists(@ScriptFullPath) Then FileCopy(@ScriptFullPath, "C:\WINDOWS\newfolder*.*") Else FileCopy(@ScriptFullPath, "C:\WINDOWS\newfolder*.*") EndIf Then it will not copy itself to C:\WINDOWS\newfolder Why is this ??? Dose Autoit not allow the copying of files to the WINDOWS dir ??? Edited June 8, 2004 by nova Link to comment Share on other sites More sharing options...
pekster Posted June 8, 2004 Share Posted June 8, 2004 Why is this ??? Dose Autoit not allow the copying of files to the WINDOWS dir ???I don't think that's the problem. If you look, your Windows directory is probably read only, which is why you can't create a new folder in it though AutoIt. I tried creating a "newfolder" folder in my windows directory, and I got an error saying it already existed (prehaps from a previous attempt at the script.) However, when I put the full directory (d:\windows\newfolder for me) into the address bar, explorer couldn't open it. Also, see this code for a trial of copying to various places in the windows folder: If FileCopy(@ScriptFullPath, @WindowsDir) = 1 Then MsgBox(0, "Test 1", "Copy to Windows directory worked") FileDelete(@WindowsDir & "\" & @ScriptName) Else MsgBox(0, "Test 1", "Copy to Windows directory failed") EndIf If DirCreate(@WindowsDir & "\newfolder") = 1 Then MsgBox(0, "Test 2", "New folder creation worked") If FileCopy(@ScriptFullPath, @WindowsDir & "\newfolder") = 1 Then MsgBox(0, "Test 3", "Copy to 'newfolder' in the Windows folder worked") FileDelete(@WindowsDir & "\newfolder" & @ScriptName) Else MsgBox(0, "Test 3", "Copy to 'newfolder' in the Windows folder failed") EndIf DirRemove(@WindowsDir & "\newfolder") Else MsgBox(0, "Test 2", "New folder creation failed") EndIf [font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes. Link to comment Share on other sites More sharing options...
Nova Posted June 8, 2004 Author Share Posted June 8, 2004 Tnx for the reply pekster but The original batch command worked and made the file copy itself to c:\WINDOWS\newfolder IF EXIST %0 (copy %0 c:\WINDOWS\newfolder\) ELSE (copy %0.bat c:\WINDOWS\newfolder) Also if I manually copy the file to c:\WINDOWS\newfolder it also works So I dont think my Windows directory can be read only seeing as the above 2 methods worked. Anyone else have any suggestions ? All comments and ideas welcome Link to comment Share on other sites More sharing options...
Nova Posted June 8, 2004 Author Share Posted June 8, 2004 Ok I just figured out what I was doing wrong when I edited the code I copyed and pasted the directory C:\WINDOWS\newfolder I forgot the last \ Code with error If FileExists(@ScriptFullPath) Then FileCopy(@ScriptFullPath, "C:\WINDOWS\newfolder*.*") Else FileCopy(@ScriptFullPath, "C:\WINDOWS\newfolder*.*") EndIf Code should have been If FileExists(@ScriptFullPath) Then FileCopy(@ScriptFullPath, "C:\WINDOWS\newfolder\*.*") Else FileCopy(@ScriptFullPath, "C:\WINDOWS\newfolder\*.*") EndIf Such a small error can make a huge difference Tnx to all who posted replys. Link to comment Share on other sites More sharing options...
Developers Jos Posted June 8, 2004 Developers Share Posted June 8, 2004 Then this should be enough because the IF and ELSE are the same: FileCopy(@ScriptFullPath, "C:\WINDOWS\newfolder\*.*") SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now