dontask Posted January 22, 2010 Share Posted January 22, 2010 I need help with the correct format for writing to a directory using a variable. Here is what I have $str = InputBox("Backup Name","Enter your Windows user name:", @UserName ) DirCreate("c:\" & $str ) so if the users name is bob $str = bob how do I copy a file to the folder called c:\bob\foldername FileCopy (" c:\ ???? \foldername Thanks for any help! Link to comment Share on other sites More sharing options...
water Posted January 22, 2010 Share Posted January 22, 2010 (edited) UseFileCopy("Sourcefile","C:\" & $str & "\foldername\") The "&" operator concatenates strings. Make sure to check that the user enters a valid name. Thats means "" would be invalid. Edited January 22, 2010 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
dontask Posted January 22, 2010 Author Share Posted January 22, 2010 (edited) UseFileCopy("Sourcefile","C:\" & $str & "\foldername") The "&" operator concatenates strings. Cool. let me try that . Thanks for the prompt response Edited January 22, 2010 by dontask Link to comment Share on other sites More sharing options...
dontask Posted January 22, 2010 Author Share Posted January 22, 2010 OK what about a Dircopy? When I try DirCopy("c:\temp\" "C:\" & $str & "\temp") I get an syntax error Link to comment Share on other sites More sharing options...
water Posted January 22, 2010 Share Posted January 22, 2010 When you check the helpfile (which is always a good idea) you will see that DirCopy needs two parameters. Parameters are (as can bee seen in the syntax diagram) separated by commas. So your statement should read: DirCopy("c:\temp\","C:\" & $str & "\temp") My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
dontask Posted January 22, 2010 Author Share Posted January 22, 2010 When you check the helpfile (which is always a good idea) you will see that DirCopy needs two parameters. Parameters are (as can bee seen in the syntax diagram) separated by commas. So your statement should read: DirCopy("c:\temp\","C:\" & $str & "\temp") Crap I looked there but over look that comma, guess I need better glasses . Thanks again!! Link to comment Share on other sites More sharing options...
dontask Posted January 22, 2010 Author Share Posted January 22, 2010 (edited) One more ... prob not the last What if the drive letter was a variable ? DirCopy("c:\temp\", & $drv & , & $str & "\temp") or DirCopy("c:\temp\", & $drv & & $str & "\temp") That didn't work Edited January 22, 2010 by dontask Link to comment Share on other sites More sharing options...
water Posted January 22, 2010 Share Posted January 22, 2010 (edited) One more ... prob not the last What if the drive letter was a variable ? DirCopy("c:\temp\", & $drv & , & $str & "\temp") or DirCopy("c:\temp\", & $drv & & $str & "\temp") That didn't work Ok, that's one of those little steps thats gets you closer being an AutoIt expert "&" concatenates two strings. The string left of "&" is concatenated to the string right of "&". So what would happen if there is no string on the left side? A comma outside of a string separates parameters. DirCopy accepts two or three parameters. So you need no comma as in example one. Please try again and then post your results of you get any error. If $drv is in the format "x:" then this should work: DirCopy("c:\temp\", $drv & "\" & $str & "\temp") Edited January 22, 2010 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
dontask Posted January 22, 2010 Author Share Posted January 22, 2010 Ok, that's one of those little steps thats gets you closer being an AutoIt expert "&" concatenates two strings. The string left of "&" is concatenated to the string right of "&". So what would happen if there is no string on the left side? A comma outside of a string separates parameters. DirCopy accepts two or three parameters. So you need no comma as in example one. Please try again and then post your results of you get any error. If $drv is in the format "x:" then this should work: DirCopy("c:\temp\", $drv & "\" & $str & "\temp") Again thanks!! DirCopy("c:\temp\", $drv & $str & "\temp") worked like a champ. Still a little confused as to why the "&" on the very left was not needed when two variables are used. Link to comment Share on other sites More sharing options...
water Posted January 22, 2010 Share Posted January 22, 2010 Again thanks!! DirCopy("c:\temp\", $drv & $str & "\temp") worked like a champ. Still a little confused as to why the "&" on the very left was not needed when two variables are used. You mix up parameters and variables. In the above example 'c:\temp\' is prameter one, '$drv & $str & "\temp"' is parameter two. Parameters are separated by commas. To concatenate variables and/or strings you need "&". My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
dontask Posted January 22, 2010 Author Share Posted January 22, 2010 Ok I think I am starting to understand it 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