none
Move specific files

    Question

  • Hi,

    I have the following code (thanks to you guys!):

    # creates a new directory with the basename of the pdf file
    ForEach($file in $containerFile){
        $rootFnNoExt = [IO.Path]::GetFilenameWithoutExtension($File)
        New-Item $rootFnNoExt -ItemType Directory | Out-Null
        
    # Extracts the pdf portfolio into the respective directory    
    ForEach($rootFnNoExt in $rootFnNoExt){
       $pdfext = C:\bill\pdftk.exe $file unpack_files output $rootFnNoExt
        
        
    # Appends the name of the directory to each of the extracted files and moves it back to the original directory
    Get-ChildItem $rootFnNoExt\* -Filter *.pdf | ForEach{
        $childFnNoExt = [IO.Path]::GetFilenameWithoutExtension($_.Name)
        #Move-Item $_.FullName (".\{0}-{1}.pdf" -f $rootFnNoExt,$childFnNoExt)
        Move-Item $_.FullName ("C:\Encrypt\portfolio\{0}-{1}.pdf" -f $rootFnNoExt,$childFnNoExt)
        
            
    # Deletes the newly created directory if it is empty   
    $LogPath = "C:\portfolio"
    Get-ChildItem -LiteralPath $LogPath -Recurse | Where-Object {
       $_.PSIsContainer -and `
        @(Get-ChildItem -LiteralPath $_.Fullname -Recurse | Where { -not $_.PSIsContainer }).Count -eq 0 } |
        Remove-Item -Recurse

    What I need to do is to move those specific files that get extracted to another directory/folder.  For example;  if I have a list of files:

    a.pdf

    b.pdf

    c.pdf

    d.pdf

    e.pdf

    f.pdf

    g.pdf

    h.pdf

    and it turns out that c.pdf and g.pdf are actually portfolios (that got extracted) then those files c.pdf and g.pdf need to be moved to another location the others stay put.  What is happening now is that c.pdf and g.pdf stay put and if I run the code again they will be extracted again.

    Any help is once again greatly appreciated.

    Thanks,

    Bernard

    Tuesday, December 15, 2015 1:58 PM

Answers

All replies