microbious Posted April 29, 2009 Posted April 29, 2009 (edited) I am good at CMD scripting and i have just now started to learn autoit. With cmd, i could copy files using commands like mkdir foldername copy "%windiwr%\filename.exe" "foldername"/Y where mkdir will create folder inside working directory. /Y is to overwrite without asking and copy will copy filename.exe from "C:\windows" folder into newly created foldername. At this point i dont understand how to use FileCopy command with autoit I tried DirCreate("saved") FileCopy ( "%systemroot%\system32\drivers\UnlockerDriver5.sys", "saved" [, flag] ) but its not working. It will create folder it curent location where executable was executed from but will not copy anything into it. I guess i dont understand the use of "Environmental Variables" use in autoit Anyone can point me to the right direction ? I have never worked with scripting languages before and all i know is CMD. Thanks in advance. Edited April 29, 2009 by stoopid
WideBoyDixon Posted April 29, 2009 Posted April 29, 2009 (edited) Take a look at EnvGet() to retrieve the value of environment variables. There are also some pre-built macros such as @SystemDir which you may be able to use. Also, don't include parameter names in the function calls (i.e. your "[, flag]" is superfluous). WBD Edited April 29, 2009 by WideBoyDixon [center]Wide by name, Wide by nature and Wide by girth[u]Scripts[/u]{Hot Folders} {Screen Calipers} {Screen Crosshairs} {Cross-Process Subclassing} {GDI+ Clock} {ASCII Art Signatures}{Another GDI+ Clock} {Desktop Goldfish} {Game of Life} {3D Pie Chart} {Stock Tracker}[u]UDFs[/u]{_FileReplaceText} {_ArrayCompare} {_ToBase}~ My Scripts On Google Code ~[/center]
Mobius Posted April 29, 2009 Posted April 29, 2009 (edited) I recommend using the the Expand environment strings option:: Opt("ExpandEnvStrings",1) ;or AutoItSetOption("ExpandEnvStrings",1) that should sort out the problem you had in this code:: DirCreate("saved") FileCopy ( "%systemroot%\system32\drivers\UnlockerDriver5.sys", "saved") Vlad Ed:useless data. Edited April 29, 2009 by Mobius
microbious Posted April 29, 2009 Author Posted April 29, 2009 (edited) can you guys show me 1 example how this DirCreate("saved") FileCopy ( "%systemroot%\system32\drivers\UnlockerDriver5.sys", "saved") would work ? Thanks ALso getting environment var is not a problem as:EnvGet("SYSTEMROOT") Problem is how to use it. I tried $var = EnvGet("SYSTEMROOT") MsgBox(4096, "Path variable is:", $var) and i get message C:\Windows But how do i use this value to copy files from there ? Example would be great. Thanks in advance Edited April 29, 2009 by stoopid
ChrisFromBoston Posted April 29, 2009 Posted April 29, 2009 This example should set you in the right direction: DirCreate("c:\myFolder") FileCopy(EnvGet("SYSTEMROOT") & "\explorer.exe", "c:\myFolder") It will create c:\myFolder and then will copy explorer from SYSTEMROOT.
microbious Posted April 29, 2009 Author Posted April 29, 2009 DirCreate("saved") FileCopy(EnvGet("SYSTEMROOT") & "system32\drivers\UnlockerDriver5.sys", "saved") doesn't work folder created in working directory as i expected, but file from system32 folder will not copy unless i enter direct path instead of ENV variable
Mobius Posted April 29, 2009 Posted April 29, 2009 (edited) DirCreate("saved") FileCopy(EnvGet("SYSTEMROOT") & "system32\drivers\UnlockerDriver5.sys", "saved") doesn't work folder created in working directory as i expected, but file from system32 folder will not copy unless i enter direct path instead of ENV variableWhat is wrong with... Opt("ExpandEnvStrings",1) ;allow the use of cmd shell %EVARS% in strings! DirCreate(@WORKINGDIR &"\saved") FileCopy ( "%systemroot%\system32\drivers\UnlockerDriver5.sys", @WORKINGDIR &"\saved") Ed: but to answer the quote, you forgot the "\" char FileCopy(EnvGet("SYSTEMROOT") & "\system32\drivers\UnlockerDriver5.sys", "saved") Edited April 29, 2009 by Mobius
microbious Posted April 29, 2009 Author Posted April 29, 2009 thanks it works. Problem is that it wont work without Opt("ExpandEnvStrings",1) I want to forget about CMD and switch to autoit and as far as i understand, Opt("ExpandEnvStrings",1) understands cmd commands. Anyway to make this work DirCreate("saved") FileCopy( "%systemroot%\system32\drivers\UnlockerDriver5.sys", "saved") without Opt("ExpandEnvStrings",1) ??????? Big thanks
ChrisFromBoston Posted April 29, 2009 Posted April 29, 2009 I don't have AutoIt on this computer, but I think the variable is @SystemRoot so it'd be: FileCopy(@SystemRoot & \system32\drivers\UnlockerDriver5.sys", "saved")
microbious Posted April 30, 2009 Author Posted April 30, 2009 i get error Error: Unterminated string. if i do DirCreate ("saved") FileCopy(@SystemRoot & "system32\drivers\UnlockerDriver5.sys", "saved") i get Line -1: Error: Unknown macro. File still not copied
microbious Posted April 30, 2009 Author Posted April 30, 2009 (edited) OK got it All i needed was FileCopy(@WindowsDir & "\system32\drivers\UnlockerDriver5.sys", "saved\", 8) I had no idea slashes could be so important Thank you all for help. Oh and one last thing, i want to create a folder in a root of current harddrive. How do i use DirCreate to accomplish that ? With CMD there was %source% as environmental variable and with autoit there is ? Edited April 30, 2009 by stoopid
CodyBarrett Posted April 30, 2009 Posted April 30, 2009 there are a whole lot of dir macros that are VERY usefull [size="1"][font="Tahoma"][COMPLETED]-----[FAILED]-----[ONGOING]VolumeControl|Binary Converter|CPU Usage| Mouse Wrap |WinHide|Word Scrammbler|LOCKER|SCREEN FREEZE|Decisions Decisions|Version UDF|Recast Desktop Mask|TCP Multiclient EXAMPLE|BTCP|LANCR|UDP serverless|AIOCR|OECR|Recast Messenger|AU3C|Tik-Tak-Toe|Snakes & Ladders|BattleShips|TRON|SNAKE_____________________[u]I love the Helpfile it is my best friend.[/u][/font][/size]
microbious Posted April 30, 2009 Author Posted April 30, 2009 (edited) yes thanks But i found DriveGetLabel ( "path" ) But this takes me back to the top of this post, Once program gets drivepath or environmental variable, how to i use it ? for exaple $var = EnvGet("WINDIR") MsgBox(4096, "Path variable is:", $var) tells me that windows in on C:\Windows Next line i want to copy file from there into somewhere else. HOW ? is it something like this ? EnvGet("WINDIR") FileCopy ("here goes what ?", "place\") confused THanks for reply. Edited April 30, 2009 by stoopid
Mobius Posted April 30, 2009 Posted April 30, 2009 (edited) How about::Ed: I forgot the trailing "\" after the 'saved' directory, so it is now &"\SAVED\" FileCopy(@SYSTEMDIR &"\drivers\UnlockerDriver5.sys",@SCRIPTDIR &"\SAVED\",9)This would copy the target file to the chosen folder, creating the folder structure if necessary,and overwriting any files in that path with the same name.Ed: As for creating a folder in a drive root...$sFname = "\NewFolder"; Remember your back slashes. no macro's end with them. DirCreate("C:" & $sFname) ;or $var = EnvGet("systemdrive") DirCreate($var & $sFname)Vlad Edited April 30, 2009 by Mobius
Juvigy Posted April 30, 2009 Posted April 30, 2009 If you have the CMD BAT file you can create CMD commands in Autoit with: RunWait(@COMSPEC & " /c del C:\124.zip /q") For example.
herewasplato Posted April 30, 2009 Posted April 30, 2009 Welcome to the forum. $var = "it is just short for variable" $anythingiwant = "yes" $"anything i want" = "no" $anything_i_want = "yes"I use it so seldom that i had to look it up in the help file that comes with the version of SciTE that I mentioned above. I don't know what all comes with (or is absent from) the SciTE-Lite that is installed with AutoIt. [size="1"][font="Arial"].[u].[/u][/font][/size]
microbious Posted May 1, 2009 Author Posted May 1, 2009 (edited) let me get this straight. RunWait(@COMSPEC & " /c del C:\124.zip /q") RunWait(@COMSPEC & "CMD commands") right ? its funny help files says Remarks To run DOS commands, try RunWait(@ComSpec & " /c " & "commandName") ; don't forget " " before "/c" Dont forget ? anyhow so i tried to RunWait(@HomeDrive & "/c " & "messagebox "window title" "message") messagebox.exe is in the same directory as built script. All i get is error line -1 and messagebox will not give me anything. If so, any chance that CMD will die out in future versions of windows ? LOL that would suck. Edited May 1, 2009 by stoopid
CodyBarrett Posted May 1, 2009 Posted May 1, 2009 if it does... then you will probably just have to recode it... shouldn't take too long but i highly doubt it will get replaced [size="1"][font="Tahoma"][COMPLETED]-----[FAILED]-----[ONGOING]VolumeControl|Binary Converter|CPU Usage| Mouse Wrap |WinHide|Word Scrammbler|LOCKER|SCREEN FREEZE|Decisions Decisions|Version UDF|Recast Desktop Mask|TCP Multiclient EXAMPLE|BTCP|LANCR|UDP serverless|AIOCR|OECR|Recast Messenger|AU3C|Tik-Tak-Toe|Snakes & Ladders|BattleShips|TRON|SNAKE_____________________[u]I love the Helpfile it is my best friend.[/u][/font][/size]
microbious Posted May 1, 2009 Author Posted May 1, 2009 (edited) well i tried any combination i could think of, and it just dont work. and why this guy referring to SciTE ? What is SciTE ? and what does it have to do with AUTOIT ? Edited May 1, 2009 by stoopid
CodyBarrett Posted May 1, 2009 Posted May 1, 2009 ScitTE is the text editor that we use for autoit... [size="1"][font="Tahoma"][COMPLETED]-----[FAILED]-----[ONGOING]VolumeControl|Binary Converter|CPU Usage| Mouse Wrap |WinHide|Word Scrammbler|LOCKER|SCREEN FREEZE|Decisions Decisions|Version UDF|Recast Desktop Mask|TCP Multiclient EXAMPLE|BTCP|LANCR|UDP serverless|AIOCR|OECR|Recast Messenger|AU3C|Tik-Tak-Toe|Snakes & Ladders|BattleShips|TRON|SNAKE_____________________[u]I love the Helpfile it is my best friend.[/u][/font][/size]
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