Delete files after conversion in Powershell -


i'm inexperienced in powershell - through trial , error have managed .doc/.docx .pdf conversion working specified folder , subfolders.

$wdformatpdf = 17 $word = new-object -comobject word.application $word.visible = $false $filetypes = "*.docx","*.doc" get-childitem -recurse -path "c:\test-acrobat" -include $filetypes | foreach-object ` {  $path =  ($_.fullname).substring(0,($_.fullname).lastindexof("."))  "converting $path pdf ..."  $doc = $word.documents.open($_.fullname)  $doc.saveas( $path, $wdformatpdf)  $doc.close() } $word.quit() 

now i'd able delete original .doc/.docx files once they've been converted. on doing searching i've found think work:

{   remove-item $filetypes  # delete file file-system } 

but i'd rather check throw in command delete files...

any appreciated. philip

i add delete inside foreach loop.

so get:

$wdformatpdf = 17 $word = new-object -comobject word.application $word.visible = $false $filetypes = "*.docx","*.doc" get-childitem -recurse -path "c:\test-acrobat" -include $filetypes | foreach-object ` {   $path =  ($_.fullname).substring(0,($_.fullname).lastindexof("."))   write-host "converting $path pdf ..."   $doc = $word.documents.open($_.fullname)   $doc.saveas( $path, $wdformatpdf)   $doc.close()   remove-item $_.fullname } $word.quit() 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -