The code above is a first attempt at a error handling copy file script. While the code appears to be executing correctly, it is not copying the file requested into the proper location as it appears to successfully do.
Thanks in advance for you assistance with this.
Can anyone shead some light on a more efficient way to accomplish this Properly.
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
When I try and execute the code above, it is returning with :
Processing file '' ...Action failed:
Error Message: Cannot bind argument to parameter 'Path' because it is null.
Script will terminate
Press Enter to continue...
ITguy565
ASKER
Sorry for my delay in responding, we are finishing preparations for a hurricane at the moment.
You're defining a scriptblock here, that the function will then just turn into its string representation. That's overly complicated and hard to understand (because the scriptblock by itself will just fail), with no benefit.
I'd recommend to just use a regular string, because that's what you need and expect anyway.
This is the only case where the scriptblock would actually work as such (so the $filenames variables are defined like that as well, I guess?).
But it would only make sense if in the time between the scriptblock's definition in the main script and the resolution in the function, the target folder you're looking for might have changed. If this folder is supposed to stay the same during the whole runtime of the script, you're better off with retrieving the folder at the script start and saving the path as a regular string.
And just in case: note that this might return more than one folder.
In other words:
Either
Replace lines 7-12 in my script above with the originals:
Or leave the script as is, and set the variables you're passing to regular strings instead of scriptblocks.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Here are the definitions for what I am using in the script. :
Open in new window
When I try and execute the code above, it is returning with :