excel - powershell move files based on csv contents -



excel - powershell move files based on csv contents -

hi , helping!

i have produced set of pdf files saved in

l:\clientsort\

each of these files has naming convention in next way

xxx_a123456_yyy.pdf xxx_300123123_yyy.pdf

(the xxx stands brand) yyy stands business relationship type)

what need move these pdf's 1 of 2 directories based on criteria within csv, excel or text file.

i perform logic of files should sent within file , within column d provide file location want move pdf.

please see attached spreadsheet farther clarify point.

basically... if pdf naming convention contains business relationship number in column a, need move file location specified in column d.

i have looked @ many different solutions possible , closed find link poss solution

anyone have ideas how may achieved?

the code have created comes multiple sources not have plenty knowledge of powershell @ time farther this.

set-location “l:\clientsort” $folders = import-csv l:\clientdatasort.csv foreach($folder in $folders) { new-item $folder.folders -type directory } $text = import-csv “l:\clientdatasort.csv” $dir = get-childitem l:\clientsort foreach($item in $text ){ foreach ($folder in $dir) { #where bundle name of column in csv file , filename name of #second column in input csv file #i not know how @ values wildcard if($item.package - accountref $folder.name){ $sourcefile = “l:\clientdatasort\” + $item.filename #i not know how export what's in column d location $target = “l:\clienddatasort” + $folder.name move-item$sourcefile$target write-host“folder $item.filename moved sucessfully $target”-foregroundcolor greenish } } }

regards

richard

$movetargets = @{} $csvfile = '.\clientdatasort.csv' $sourcefolder = 'l:\clientsort' foreach ($record in import-csv -path $csvfile) { $movetargets[$record.accountref] = $record.filesortlocation } get-childitem -path $sourcefolder | foreach-object { $pdffile = $_ if ($pdffile.name -match '^[^_]*_([^_]*)_[^_]*\.pdf$') { $accountref = $matches[1] $target = $movetargets[$accountref] if ($target) { move-item -path $pdffile.fullname -destination $target } }

}

excel powershell pdf csv

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -