copy file - create folder if not exits..

Topics: Archive - General
Nov 28, 2013 at 10:08 AM

how would you do the following with psapp script:
  1. check if folder exists, if not create it, if exists don't do any more.
  2. copy ALL files from appdeployscripts "files" folder
  3. register-dll (this part I haven't gotten to yet.)
I've tried execute-process with arguments ""mkdir %windir%\SysWOW64\srs_rpe"" but here I can't check if folder exists OR just force it..

I tried: Execute-Process -filepath "cmd.exe" -Arguments "IF exist %windir%\SysWOW64\srs_rpe (echo srs_rpe exists) ELSE mkdir %windir%\SysWOW64\srs_rpe" -ContinueOnError

but this just hangs and gets nowhere

There must be an easier way..

Any ideas?
Nov 28, 2013 at 12:03 PM
You can do this all in PowerShell very easily. This relies on the the Toolkit functions and logs everything for you:
    # Create folder if it doesn't exist
    If (!(Test-Path -Path "$envProgramFilesX86\Testing" -ErrorAction SilentlyContinue )) { New-Item "$envProgramFilesX86\Testing") -Type Directory -ErrorAction SilentlyContinue | Out-Null }

    # Copy each file in the Files folder
    ForEach ($file in (Get-ChildItem $dirFiles)) {
        Copy-File -Path ($file.FullName) -Destination "$envProgramFilesX86\Testing\($file.Name)"

    # Register DLL
    Register-DLL "$envProgramFilesX86\Testing\MyFile.DLL"
Should work :)

Marked as answer by Symbiot on 11/28/2013 at 7:21 AM
Nov 28, 2013 at 12:52 PM
Hi Dan..

thx so much.. However a few changes had to be made..

I deleted : { New-Item "$envProgramFilesX86\Testing") .. the last ")"

and.. I removed ($file.Name) since it copied the files as:


Nov 28, 2013 at 12:54 PM
Woops, sorry, I hadn't tested it. Just threw it together in Notepad quickly :)

($file.Name) was actually meant to be $($file.Name)
Nov 28, 2013 at 12:56 PM
at least.. that was neccessary to make it work for me..
is it unwise to make these changes?
Nov 28, 2013 at 12:57 PM
Nope they should be fine
Nov 28, 2013 at 12:58 PM
I changed it back to $($file.Name),,, muuuuuch better! :-)
Nov 28, 2013 at 3:21 PM
Thx for your help Dan.. it fixed my problem.