Powershell Convert new files to tiff












0














I have a powershell script that I frankensteined together that looks at a folder for newly added files, then moves those files to another folder that then gets converted using ghostscript to a .tif. After that all .pdf's get moved to a PDF folder and all tiffs get moved to a TIF folder. When complete it makes a log entry to a txt file. Any new files that get dropped into the Import folder trigger this script to run again.



The issues I'm having:




  1. The converted Tiffs have "TIF" in front of the file name, I do not want that, just the same name as the pdf it was created from.

  2. When a second file is converted it creates a copy of the last converted file and sticks it in the root folder. Not sure why that is. But I only want one copy of the tif, and it to be put in the TIF folder.


Hope someone can tell me what I'm doing wrong!



Code:



### SET FOLDER TO WATCH + FILES TO WATCH + SUBFOLDERS YES/NO
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = "C:FolderImport"
$watcher.Filter = "*.*"
$watcher.IncludeSubdirectories = $false
$watcher.EnableRaisingEvents = $true

### DEFINE ACTIONS AFTER AN EVENT IS DETECTED
$action = {

$path = $Event.SourceEventArgs.FullPath
$changeType = $Event.SourceEventArgs.ChangeType
$logline = "$(Get-Date), $changeType, $path"
Add-content "C:Folderlog.txt" -value $logline

#Path to your Ghostscript EXE
$tool = 'C:Program Filesgsgs9.26bingswin64c.exe'
#Directory containing the PDF files that will be converted
$inputDir = 'C:Folder'
#.pdf Files
$pdfDir = 'C:Folder*.pdf'
#.tif Files
$tifDir = 'C:Folder*.tif'
#Directory catchall for all incoming files.
$dumpDir = 'C:FolderImport*.*'
#Output path where converted PDF files will be stored
$pdfOutputDir = 'C:FolderPDF'
#Output path where the TIF files will be saved
$tifOutputDir = 'C:FolderTIF'

Get-ChildItem -Path $dumpDir -Recurse -File | Move-Item -Destination $inputDir
$pdfs = get-childitem $inputDir -recurse | where {$_.Extension -match "pdf"}

foreach($pdf in $pdfs)
{
$tif = $tifOutputDir + $pdf.BaseName + ".tif"
if(test-path $tif)
{
"tif file already exists " + $tif
}
else
{
'Processing ' + $pdf.Name
$param = "-sOutputFile=$tif"
& $tool -q -dNOPAUSE -sDEVICE=tiffg4 $param -r300 $pdf.FullName -c quit
}
Get-ChildItem -Path $pdfDir -Recurse -File | Move-Item -Destination $pdfOutputDir
Get-ChildItem -Path $tifDir -Recurse -File | Move-Item -Destination $tifOutputDir
}

}
### DECIDE WHICH EVENTS SHOULD BE WATCHED
Register-ObjectEvent $watcher "Created" -Action $action
while ($true) {sleep 5}









share|improve this question
























  • Please don't edit the answer into your question. Super User is a question and answer site and answers should be separate from questions. You can answer your own question instead.
    – DavidPostill
    Dec 19 '18 at 13:40
















0














I have a powershell script that I frankensteined together that looks at a folder for newly added files, then moves those files to another folder that then gets converted using ghostscript to a .tif. After that all .pdf's get moved to a PDF folder and all tiffs get moved to a TIF folder. When complete it makes a log entry to a txt file. Any new files that get dropped into the Import folder trigger this script to run again.



The issues I'm having:




  1. The converted Tiffs have "TIF" in front of the file name, I do not want that, just the same name as the pdf it was created from.

  2. When a second file is converted it creates a copy of the last converted file and sticks it in the root folder. Not sure why that is. But I only want one copy of the tif, and it to be put in the TIF folder.


Hope someone can tell me what I'm doing wrong!



Code:



### SET FOLDER TO WATCH + FILES TO WATCH + SUBFOLDERS YES/NO
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = "C:FolderImport"
$watcher.Filter = "*.*"
$watcher.IncludeSubdirectories = $false
$watcher.EnableRaisingEvents = $true

### DEFINE ACTIONS AFTER AN EVENT IS DETECTED
$action = {

$path = $Event.SourceEventArgs.FullPath
$changeType = $Event.SourceEventArgs.ChangeType
$logline = "$(Get-Date), $changeType, $path"
Add-content "C:Folderlog.txt" -value $logline

#Path to your Ghostscript EXE
$tool = 'C:Program Filesgsgs9.26bingswin64c.exe'
#Directory containing the PDF files that will be converted
$inputDir = 'C:Folder'
#.pdf Files
$pdfDir = 'C:Folder*.pdf'
#.tif Files
$tifDir = 'C:Folder*.tif'
#Directory catchall for all incoming files.
$dumpDir = 'C:FolderImport*.*'
#Output path where converted PDF files will be stored
$pdfOutputDir = 'C:FolderPDF'
#Output path where the TIF files will be saved
$tifOutputDir = 'C:FolderTIF'

Get-ChildItem -Path $dumpDir -Recurse -File | Move-Item -Destination $inputDir
$pdfs = get-childitem $inputDir -recurse | where {$_.Extension -match "pdf"}

foreach($pdf in $pdfs)
{
$tif = $tifOutputDir + $pdf.BaseName + ".tif"
if(test-path $tif)
{
"tif file already exists " + $tif
}
else
{
'Processing ' + $pdf.Name
$param = "-sOutputFile=$tif"
& $tool -q -dNOPAUSE -sDEVICE=tiffg4 $param -r300 $pdf.FullName -c quit
}
Get-ChildItem -Path $pdfDir -Recurse -File | Move-Item -Destination $pdfOutputDir
Get-ChildItem -Path $tifDir -Recurse -File | Move-Item -Destination $tifOutputDir
}

}
### DECIDE WHICH EVENTS SHOULD BE WATCHED
Register-ObjectEvent $watcher "Created" -Action $action
while ($true) {sleep 5}









share|improve this question
























  • Please don't edit the answer into your question. Super User is a question and answer site and answers should be separate from questions. You can answer your own question instead.
    – DavidPostill
    Dec 19 '18 at 13:40














0












0








0







I have a powershell script that I frankensteined together that looks at a folder for newly added files, then moves those files to another folder that then gets converted using ghostscript to a .tif. After that all .pdf's get moved to a PDF folder and all tiffs get moved to a TIF folder. When complete it makes a log entry to a txt file. Any new files that get dropped into the Import folder trigger this script to run again.



The issues I'm having:




  1. The converted Tiffs have "TIF" in front of the file name, I do not want that, just the same name as the pdf it was created from.

  2. When a second file is converted it creates a copy of the last converted file and sticks it in the root folder. Not sure why that is. But I only want one copy of the tif, and it to be put in the TIF folder.


Hope someone can tell me what I'm doing wrong!



Code:



### SET FOLDER TO WATCH + FILES TO WATCH + SUBFOLDERS YES/NO
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = "C:FolderImport"
$watcher.Filter = "*.*"
$watcher.IncludeSubdirectories = $false
$watcher.EnableRaisingEvents = $true

### DEFINE ACTIONS AFTER AN EVENT IS DETECTED
$action = {

$path = $Event.SourceEventArgs.FullPath
$changeType = $Event.SourceEventArgs.ChangeType
$logline = "$(Get-Date), $changeType, $path"
Add-content "C:Folderlog.txt" -value $logline

#Path to your Ghostscript EXE
$tool = 'C:Program Filesgsgs9.26bingswin64c.exe'
#Directory containing the PDF files that will be converted
$inputDir = 'C:Folder'
#.pdf Files
$pdfDir = 'C:Folder*.pdf'
#.tif Files
$tifDir = 'C:Folder*.tif'
#Directory catchall for all incoming files.
$dumpDir = 'C:FolderImport*.*'
#Output path where converted PDF files will be stored
$pdfOutputDir = 'C:FolderPDF'
#Output path where the TIF files will be saved
$tifOutputDir = 'C:FolderTIF'

Get-ChildItem -Path $dumpDir -Recurse -File | Move-Item -Destination $inputDir
$pdfs = get-childitem $inputDir -recurse | where {$_.Extension -match "pdf"}

foreach($pdf in $pdfs)
{
$tif = $tifOutputDir + $pdf.BaseName + ".tif"
if(test-path $tif)
{
"tif file already exists " + $tif
}
else
{
'Processing ' + $pdf.Name
$param = "-sOutputFile=$tif"
& $tool -q -dNOPAUSE -sDEVICE=tiffg4 $param -r300 $pdf.FullName -c quit
}
Get-ChildItem -Path $pdfDir -Recurse -File | Move-Item -Destination $pdfOutputDir
Get-ChildItem -Path $tifDir -Recurse -File | Move-Item -Destination $tifOutputDir
}

}
### DECIDE WHICH EVENTS SHOULD BE WATCHED
Register-ObjectEvent $watcher "Created" -Action $action
while ($true) {sleep 5}









share|improve this question















I have a powershell script that I frankensteined together that looks at a folder for newly added files, then moves those files to another folder that then gets converted using ghostscript to a .tif. After that all .pdf's get moved to a PDF folder and all tiffs get moved to a TIF folder. When complete it makes a log entry to a txt file. Any new files that get dropped into the Import folder trigger this script to run again.



The issues I'm having:




  1. The converted Tiffs have "TIF" in front of the file name, I do not want that, just the same name as the pdf it was created from.

  2. When a second file is converted it creates a copy of the last converted file and sticks it in the root folder. Not sure why that is. But I only want one copy of the tif, and it to be put in the TIF folder.


Hope someone can tell me what I'm doing wrong!



Code:



### SET FOLDER TO WATCH + FILES TO WATCH + SUBFOLDERS YES/NO
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = "C:FolderImport"
$watcher.Filter = "*.*"
$watcher.IncludeSubdirectories = $false
$watcher.EnableRaisingEvents = $true

### DEFINE ACTIONS AFTER AN EVENT IS DETECTED
$action = {

$path = $Event.SourceEventArgs.FullPath
$changeType = $Event.SourceEventArgs.ChangeType
$logline = "$(Get-Date), $changeType, $path"
Add-content "C:Folderlog.txt" -value $logline

#Path to your Ghostscript EXE
$tool = 'C:Program Filesgsgs9.26bingswin64c.exe'
#Directory containing the PDF files that will be converted
$inputDir = 'C:Folder'
#.pdf Files
$pdfDir = 'C:Folder*.pdf'
#.tif Files
$tifDir = 'C:Folder*.tif'
#Directory catchall for all incoming files.
$dumpDir = 'C:FolderImport*.*'
#Output path where converted PDF files will be stored
$pdfOutputDir = 'C:FolderPDF'
#Output path where the TIF files will be saved
$tifOutputDir = 'C:FolderTIF'

Get-ChildItem -Path $dumpDir -Recurse -File | Move-Item -Destination $inputDir
$pdfs = get-childitem $inputDir -recurse | where {$_.Extension -match "pdf"}

foreach($pdf in $pdfs)
{
$tif = $tifOutputDir + $pdf.BaseName + ".tif"
if(test-path $tif)
{
"tif file already exists " + $tif
}
else
{
'Processing ' + $pdf.Name
$param = "-sOutputFile=$tif"
& $tool -q -dNOPAUSE -sDEVICE=tiffg4 $param -r300 $pdf.FullName -c quit
}
Get-ChildItem -Path $pdfDir -Recurse -File | Move-Item -Destination $pdfOutputDir
Get-ChildItem -Path $tifDir -Recurse -File | Move-Item -Destination $tifOutputDir
}

}
### DECIDE WHICH EVENTS SHOULD BE WATCHED
Register-ObjectEvent $watcher "Created" -Action $action
while ($true) {sleep 5}






powershell autorun ghostscript






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 19 '18 at 13:40









DavidPostill

103k25223257




103k25223257










asked Dec 18 '18 at 23:47









Tohny.Johnson

12




12












  • Please don't edit the answer into your question. Super User is a question and answer site and answers should be separate from questions. You can answer your own question instead.
    – DavidPostill
    Dec 19 '18 at 13:40


















  • Please don't edit the answer into your question. Super User is a question and answer site and answers should be separate from questions. You can answer your own question instead.
    – DavidPostill
    Dec 19 '18 at 13:40
















Please don't edit the answer into your question. Super User is a question and answer site and answers should be separate from questions. You can answer your own question instead.
– DavidPostill
Dec 19 '18 at 13:40




Please don't edit the answer into your question. Super User is a question and answer site and answers should be separate from questions. You can answer your own question instead.
– DavidPostill
Dec 19 '18 at 13:40










0






active

oldest

votes











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1385737%2fpowershell-convert-new-files-to-tiff%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Super User!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1385737%2fpowershell-convert-new-files-to-tiff%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

Mangá

 ⁒  ․,‪⁊‑⁙ ⁖, ⁇‒※‌, †,⁖‗‌⁝    ‾‸⁘,‖⁔⁣,⁂‾
”‑,‥–,‬ ,⁀‹⁋‴⁑ ‒ ,‴⁋”‼ ⁨,‷⁔„ ‰′,‐‚ ‥‡‎“‷⁃⁨⁅⁣,⁔
⁇‘⁔⁡⁏⁌⁡‿‶‏⁨ ⁣⁕⁖⁨⁩⁥‽⁀  ‴‬⁜‟ ⁃‣‧⁕‮ …‍⁨‴ ⁩,⁚⁖‫ ,‵ ⁀,‮⁝‣‣ ⁑  ⁂– ․, ‾‽ ‏⁁“⁗‸ ‾… ‹‡⁌⁎‸‘ ‡⁏⁌‪ ‵⁛ ‎⁨ ―⁦⁤⁄⁕