locked
Moving Files inside folders using csv RRS feed

  • Question

  • I am looking to use powershell to compile a lot of drawings that are stored in separate folders using an excel document or .csv

    The structure of the excel file as follows:

    Folder to Set Up | Drawing 1 | Drawing 2 | Drawing 3 | Drawing 4 | Drawing 5

    AAA-AA1               | BBB-B1       | C-CCCC1    | EEEE-E1     | FFF-FFF-1   | GGG-GGG1

    AAA-AA2               | BBB-B2       | C-CCCC2    | EEEE-E2     | FFF-FFF-2   | GGG-GGG2

    AAA-AA3               | BBB-B3       | C-CCCC3     | EEEE-E3     |FFF-FFF-3   | GGG-GGG3

    All drawings of the same type are stored in the same sub-folder.

    filepaths are C:\\Users\XXXX\Desktop\NewCompiledFolder

                      C:\\Users\XXXX\Desktop\OldFolder\Drawing1

                      C:\\Users\XXXX\Desktop\OldFolder\Drawing2

                      C:\\Users\XXXX\Desktop\OldFolder\Drawing3

                      C:\\Users\XXXX\Desktop\OldFolder\Drawing4

                      C:\\Users\XXXX\Desktop\OldFolder\Drawing5

    Can someone help me with this code?

    Thanks,

    Mike

    Friday, May 25, 2018 12:01 AM

All replies

  • No idea what you are asking?  What does "compile a lot of drawings " mean.  PowerShell cannot compile anything.  Perhaps you have a vendor program that you can get help for from the vendors forum.

    \_(ツ)_/

    Friday, May 25, 2018 12:17 AM
  • I'm not sure and the logic for each drawing is open on the switch.

    [CmdletBinding()]
    
    $path="$env:USERPROFILE\Desktop\OldFolder"
    $selected=@()
    Import-csv .\fileO.csv -Delimiter "|"  | ForEach-Object{
        $CurrentObject = $_
        $folder="$path\$($_."Folder To Set Up")"
        if(!(Test-path $folder)){
            [System.IO.Directory]::CreateDirectory($folder) | Out-Null
        }
        
        #Setup Folders
        $CurrentObject.PSobject.Properties |%{
            $obj=$_
            #remove any empty space
            $name= ([string]$obj.Name).Replace(" ","")
    
            switch($name){
                "FolderToSetUp" {}
                default{
                    if(!(Test-path "$folder\$name")){
                        [System.IO.Directory]::CreateDirectory("$folder\$name") | Out-Null
                    }
    
                    if($_ -match 1){
                        #Logic for Drawing 1
                        Write-Host -ForegroundColor Cyan $obj.value
                    }
    
                    if($_ -match 2){
                        #Logic for Drawing 2
                        Write-Host -ForegroundColor Cyan $obj.value
                    }
    
                    if($_ -match 3){
                        #Logic for Drawing 3
                        Write-Host -ForegroundColor Cyan $obj.value
                    }
    
                    if($_ -match 4){
                        #Logic for Drawing 4
                        Write-Host -ForegroundColor Cyan $obj.value
                    }
    
                    if($_ -match 5){
                        #Logic for Drawing 5
                        Write-Host -ForegroundColor Cyan $obj.value
                    }
    
    
                }
            }
        }
        
    }
    Write-Output $selected.Column2
    Remove-Variable Selected

    Friday, May 25, 2018 7:25 AM