Jump to content
Sign in to follow this  
dontask

Newbie needs help with variables

Recommended Posts

dontask

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!

Share this post


Link to post
Share on other sites
water

Use

FileCopy("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 by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
dontask

Use

FileCopy("Sourcefile","C:\" & $str & "\foldername")

The "&" operator concatenates strings.

Cool. let me try that . Thanks for the prompt response

Edited by dontask

Share this post


Link to post
Share on other sites
dontask

OK what about a Dircopy? When I try

DirCopy("c:\temp\" "C:\" & $str & "\temp")

I get an syntax error

Share this post


Link to post
Share on other sites
water

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 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
dontask

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!!

Share this post


Link to post
Share on other sites
dontask

One more ... prob not the last :D 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 by dontask

Share this post


Link to post
Share on other sites
water

One more ... prob not the last :D 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 :huggles:

"&" 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 by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
dontask

Ok, that's one of those little steps thats gets you closer being an AutoIt expert :D

"&" 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. :huggles:

Share this post


Link to post
Share on other sites
water

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. :D

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 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
dontask

Ok I think I am starting to understand it :D

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×