Jump to content

Newbie needs help with variables


dontask
 Share

Recommended Posts

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

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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 - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

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
Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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:

Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...