none
newly created current date folder have issue to move files in it from destination RRS feed

  • Question



  • in this already existing folder I want to move that file

    $rootpath = "D:\SSIS_Package_Deployments\"
    $e = "ssisname"
    $m = "\"
    $de = New-Item $rootpath$e$m"Deployment_$((get-date).toString('yyyyMMdd'))" -type directory
    if(-not (Test-Path $de)) { New-Item $rootpath$e$m"Deployment_$((get-date).toString('yyyyMMdd'))" | out-null}
    
    foreach ($i in Get-ChildItem -Path $de -Recurse)
    {
    
        if (($i.Name -match "Deployment_$((get-date).toString('yyyyMMdd'))") )
        {
            echo $i.Name
            Move-Item c:\temp\STA\*.dtsConfig $i.Name -confirm
        }
    }

    err:New-Item : Item with specified name D:\SSIS_Package_Deployments\ODMamImport1\Deployment_20130606 already exists.

    At line:5 char:15
    + $de = New-Item <<<<  $rootpath$e$m"Deployment_$((get-date).toString('yyyyMMdd'))" -type directory
        + CategoryInfo          : ResourceExists: (D:\SSIS_Package...oyment_20130606:String) [New-Item], IOException
        + FullyQualifiedErrorId : DirectoryExist,Microsoft.PowerShell.Commands.NewItemCommand

    Test-Path : Cannot bind argument to parameter 'Path' because it is null.
    At line:6 char:19
    + if(-not (Test-Path <<<<  $de)) { New-Item $rootpath$e$m"Deployment_$((get-date).toString('yyyyMMdd'))" | out-null}
        + CategoryInfo          : InvalidData: (:) [Test-Path], ParameterBindingValidationException
        + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.TestPathCommand

     

    --Himanshu Kulkarni

    Friday, June 7, 2013 11:57 AM

Answers

  • OK I did write a reply detailing my what my code did ...seeing as I accidently pressed the back button on my browser I'll be brief: (grrrr to my stupidity!!)

    The only change you are trying to do that I can see in the above is to change the name of the dstination dir to: $rootpath$e$m"Deployment_$((get-date).toString('yyyyMMdd'))"

    If this is indeed the case then the following code will work

    $rootpath="E:\SSIS_Package_Deployments\"
    $e="ODMamImport1"
    $m="\"+"Deployment_$((get-date).toString('yyyyMMdd'))"
    $OldPath = Get-ChildItem -Path "c:\temp\STA\" -Recurse
    $FileName = ".dtsConfig"
    $NewPath = $rootpath+$e+$m
    If (Test-Path $NewPath)
      {
        ForEach ($Item in $OldPath)
          {
            If ($Item.Name -match $FileName)
              {
                Move-Item $Item.FullName $NewPath -Force
                Write-Host $Item.Name
              }
          }
      }
    Else
      {
        New-Item $NewPath -type directory
        ForEach ($Item in $OldPath)
          {
            If ($Item.Name -match $FileName)
              {
                Move-Item $Item.FullName $NewPath -Force
                Write-Host $Item.Name
              }
          }
      }
    Hope this helps

    Monday, June 17, 2013 2:54 PM

All replies

  • Try changing your $de var to this:

    $rootpath+$e+$m+"Deployment_$((get-date).toString('yyyyMMdd'))"

    ...same with the new item command on the line underneath

    Cheers

    Monday, June 10, 2013 8:06 AM
  • it is creating ++folder and nothing else, from my script I am getting error as folder already exists and in this already exists folder I want to move files 

    $rootpath="D:\SSIS_Package_Deployments\"
    $e="ODMamImport1"
    $m="\"
    $de = New-Item $rootpath$e$m"Deployment_$((get-date).toString('yyyyMMdd'))" -type directory

    while ($de){
      Move-Item c:\temp\STA\*.dtsConfig $de 
      exit
     }
    New-Item : Item with specified name D:\SSIS_Package_Deployments\ODMamImport1\Deployment_20130611 already exists.
    At line:4 char:15
    + $de = New-Item <<<<  $rootpath$e$m"Deployment_$((get-date).toString('yyyyMMdd'))" -type directory
        + CategoryInfo          : ResourceExists: (D:\SSIS_Package...oyment_20130611:String) [New-Item], IOException
        + FullyQualifiedErrorId : DirectoryExist,Microsoft.PowerShell.Commands.NewItemCommand


    --Himanshu Kulkarni

    Tuesday, June 11, 2013 9:38 AM
  • Did you change the $de variable? In its current state (as indicated by your paste above) it will not work ...you need to concatenate the $rootpath, $e and $m var. To do that you need to join them using + as my first reply demonstrated. Without that the script will error at the beginning

    ^^Ignore above

    EDIT:

    OK after re-reading (clearly I havent woken up yet I understand what you mean)

    How about using the -Force Switch when creating the directory to allow creation if the path exists

    $de = New-Item $rootpath$e$m"Deployment_$((get-date).toString('yyyyMMdd'))" -type directory -Force

    • Edited by IT Badger Tuesday, June 11, 2013 11:05 AM Finally Woke Up
    Tuesday, June 11, 2013 9:58 AM
  • Another point while I'm on lunch ...if all you're trying to do is move 1 file called Deployment_$((get-date).toString('yyyyMMdd')) from c:\temp\STA\ to your D:\SSIS_Package_Deployments\ODMamImport1 folder why not use something like:

    $rootpath="E:\SSIS_Package_Deployments\"
    $e="ODMamImport1"
    $m="\"
    $OldPath = Get-ChildItem -Path "c:\temp\STA\" -Recurse
    $FileName = "Deployment_$((get-date).toString('yyyyMMdd'))"
    $NewPath = $rootpath+$e+$m+$FileName
    If (Test-Path $NewPath)
      {
        ForEach ($Item in $OldPath)
          {
            If ($Item.Name -match $FileName)
              {
                Move-Item $Item.FullName $NewPath -Force
                Write-Host $Item.Name
              }
          }
      }
    Else
      {
        New-Item $NewPath -type directory
        ForEach ($Item in $OldPath)
          {
            If ($Item.Name -match $FileName)
              {
                Move-Item $Item.FullName $NewPath -Force
                Write-Host $Item.Name
              }
          }
      }
    Cheers
    Tuesday, June 11, 2013 11:57 AM
  • sorry to not gives you explanation

    there is *.dtsConfig file at c:\temp\STA\ I want to move to just newly created folder called $de = New-Item $rootpath$e$m"Deployment_$((get-date).toString('yyyyMMdd'))" -type directory

    but it gives error as New-Item : Item with specified name D:\SSIS_Package_Deployments\ODMamImport1\Deployment_20130611 already exists., I want to insert *.dtsConfig file in this already exists path 

    you think there is some date time file but now some date time folder is created called Deployment_20130611 and I want to move *dtsConfig file from c:\temp\STA\ to this deployment folder 


    --Himanshu Kulkarni

    Tuesday, June 11, 2013 1:43 PM
  • $rootpath="E:\SSIS_Package_Deployments\"
    $e="ODMamImport1"
    $m="\"
    $OldPath = Get-ChildItem -Path "c:\temp\STA\" -Recurse
    $FileName = ".dtsConfig"
    $NewPath = $rootpath+$e+$m+$FileName
    If (Test-Path $NewPath)
      {
        ForEach ($Item in $OldPath)
          {
            If ($Item.Name -match $FileName)
              {
                Move-Item $Item.FullName $NewPath -Force
                Write-Host $Item.Name
              }
          }
      }
    Else
      {
        New-Item $NewPath -type directory
        ForEach ($Item in $OldPath)
          {
            If ($Item.Name -match $FileName)
              {
                Move-Item $Item.FullName $NewPath -Force
                Write-Host $Item.Name
              }
          }
      }

    Sorry for the delay it's been a manic few days here at work.

    Ok so the above will grab any files within the c:\temp\STA\ folder that have ".dtsconfig" in the file name (be it the file extension or part of the file name) and will move them to E:\SSIS_Package_Deployments\ODMamImport1. If the E:\SSIS_Package_Deployments\ODMamImport1 directory doesnt exist the it will be created automatically. If it does exist then the items will be moved into that existing directory. Note that if there are any *.dtsconfig files in the destination directory with the same names as those that are being moved then they will be overwritten. You can stop this by removing the -force switch from the move-item lines in the above script. This will cause the script to error when it encounters a duplicate file name

    I suppose this error could be caught and the file renamed  etc ...upt o you

    Cheers

    Friday, June 14, 2013 7:44 AM
  • you are too close, replace $FileName with below string

    $FileName = New-Item $rootpath$e$m"Deployment_$((get-date).toString('yyyyMMdd'))" -type directory

    now getting error: 

    New-Item : Item with specified name D:\SSIS_Package_Deployments\ODMamImport1\Deployment_20130617 already exists.
    At line:6 char:21
    + $FileName = New-Item <<<<  $rootpath$e$m"Deployment_$((get-date).toString('yyyyMMdd'))" -type directory
        + CategoryInfo          : ResourceExists: (D:\SSIS_Package...oyment_20130617:String) [New-Item], IOException
        + FullyQualifiedErrorId : DirectoryExist,Microsoft.PowerShell.Commands.NewItemCommand

    the problem is that for just newly created folder Deployment_20130617, *.config file (c:\temp\STA\*.config) is not getting moved into this folder and gives above error 

    this config file is moved just to D:\SSIS_Package_Deployments\ODMamImport1 and it should be moved to D:\SSIS_Package_Deployments\ODMamImport1\Deployment_20130617

    ------------------------------------------------

    tried one more but now it gives NULL PATH:

    $rootpath="D:\SSIS_Package_Deployments\"
    $e="ODMamImport1"
    $m="\"
    $OldPath = Get-ChildItem -Path "c:\temp\STA\" -Recurse
    $FileName1 = ".dtsConfig"
    echo $FileName = New-Item $rootpath$e$m"Deployment_$((get-date).toString('yyyyMMdd'))" -type directory

    #echo $NewPath 
    #echo $FileName

    If (Test-Path $FileName)
      {
        ForEach ($Item in $OldPath)
          {
            If ($Item.Name -match $FileName)
              {
                Move-Item $Item.FullName $FileName -confirm -Force 
                Write-Host $Item.Name
              }
          }
      }
    Else
      {
        New-Item $NewPath -type directory
        ForEach ($Item in $OldPath)
          {
            If ($Item.Name -match $FileName)
              {
                Move-Item $Item.FullName $FileName -confirm -Force
                Write-Host $Item.Name
              }
          }
      }

    now it gives path as null:

    Test-Path : Cannot bind argument to parameter 'Path' because it is null.
    At line:11 char:14
    + If (Test-Path <<<<  $FileName)
        + CategoryInfo          : InvalidData: (:) [Test-Path], ParameterBindingValidationException
        + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.TestPathCommand

      



    --Himanshu Kulkarni




    Monday, June 17, 2013 12:59 PM
  • OK I did write a reply detailing my what my code did ...seeing as I accidently pressed the back button on my browser I'll be brief: (grrrr to my stupidity!!)

    The only change you are trying to do that I can see in the above is to change the name of the dstination dir to: $rootpath$e$m"Deployment_$((get-date).toString('yyyyMMdd'))"

    If this is indeed the case then the following code will work

    $rootpath="E:\SSIS_Package_Deployments\"
    $e="ODMamImport1"
    $m="\"+"Deployment_$((get-date).toString('yyyyMMdd'))"
    $OldPath = Get-ChildItem -Path "c:\temp\STA\" -Recurse
    $FileName = ".dtsConfig"
    $NewPath = $rootpath+$e+$m
    If (Test-Path $NewPath)
      {
        ForEach ($Item in $OldPath)
          {
            If ($Item.Name -match $FileName)
              {
                Move-Item $Item.FullName $NewPath -Force
                Write-Host $Item.Name
              }
          }
      }
    Else
      {
        New-Item $NewPath -type directory
        ForEach ($Item in $OldPath)
          {
            If ($Item.Name -match $FileName)
              {
                Move-Item $Item.FullName $NewPath -Force
                Write-Host $Item.Name
              }
          }
      }
    Hope this helps

    Monday, June 17, 2013 2:54 PM