P
patters78
Guest
Hi everyone
Firstly i do apologise if this isn't the correct forum to be posting this question.
Secondly you'll soon discover that i really don't know much about PowerShell or Visual Studio but i'm learning... I'm Sure the Powershell script your gonna see could be better but it works..
So my issue was with a system that outputted txt files onto 2 PC's LH & RH these txt files was outputted with different name's as it was using 3 different products, We then needed these files to be filtered by product and copied to two network drives while also being archived and deleted from the original folder.. Oh and this needed to be done real time.
So my Powershell script ive been using is the following
<code>
$folder = 'Target Folder'
$timeout = 1000
$filesystemwatcher = new-object system.IO.filesystemwatcher $folder
write-host "Monitoring... $folder
Transfering..."
while ($true) {
$result = $FileSystemWatcher.WaitForChanged('all', $timeout)
if ($result.timeout -eq $false)
{
write-warning ('file {0} : {1}' -f $result.changetype, $result.name)
}
$targetdirectory = "Target folder"
$sourcedirectory = "export folder"
if (-not(Test-Path -path $targetdirectory)){
New-Item $targetdirectory -Type Directory}
Copy-Item -Path $sourcedirectory\"*.txt" -Destination $targetdirectory
$Files = Get-ChildItem -Path export folder -Filter "*.txt" -Recurse
foreach($File in $Files)
{
if ($File.name -like "1*.txt")
{
Move-Item -Path $File.FullName "1 folder"
}
elseif ($File.name -like "2*.txt")
{
Move-Item -Path $File.FullName "2 folder"
}
elseif ($File.name -like "3*.txt")
{
Move-Item -Path $File.FullName "3 folder"
}
}
}
</code>
Now this script gets the files moved and works but its a Powershell script and its running 24/7 365 days a year sometimes the script had stopped sometimes the script has been messed with its just not reliable enough.
So i want to turn it into a application via Visual studio..
Is it possible? remember i have never used Visual Studio before (Been trying it for a few hours learnt some basics)
Has anyone done anything similar to this before/ is there any guide anyone can think of that would suit my needs more?
Im looking for the application to have the following
A status screen ie what files it has found and where it has moved them to.
A setting option to be able to set.. amount of filter string/save paths... change source & export/archive paths etc
Can anyone point me in the right direction? being new i don't know what to search for to get guides on my needs
Cheers
Continue reading...
Firstly i do apologise if this isn't the correct forum to be posting this question.
Secondly you'll soon discover that i really don't know much about PowerShell or Visual Studio but i'm learning... I'm Sure the Powershell script your gonna see could be better but it works..
So my issue was with a system that outputted txt files onto 2 PC's LH & RH these txt files was outputted with different name's as it was using 3 different products, We then needed these files to be filtered by product and copied to two network drives while also being archived and deleted from the original folder.. Oh and this needed to be done real time.
So my Powershell script ive been using is the following
<code>
$folder = 'Target Folder'
$timeout = 1000
$filesystemwatcher = new-object system.IO.filesystemwatcher $folder
write-host "Monitoring... $folder
Transfering..."
while ($true) {
$result = $FileSystemWatcher.WaitForChanged('all', $timeout)
if ($result.timeout -eq $false)
{
write-warning ('file {0} : {1}' -f $result.changetype, $result.name)
}
$targetdirectory = "Target folder"
$sourcedirectory = "export folder"
if (-not(Test-Path -path $targetdirectory)){
New-Item $targetdirectory -Type Directory}
Copy-Item -Path $sourcedirectory\"*.txt" -Destination $targetdirectory
$Files = Get-ChildItem -Path export folder -Filter "*.txt" -Recurse
foreach($File in $Files)
{
if ($File.name -like "1*.txt")
{
Move-Item -Path $File.FullName "1 folder"
}
elseif ($File.name -like "2*.txt")
{
Move-Item -Path $File.FullName "2 folder"
}
elseif ($File.name -like "3*.txt")
{
Move-Item -Path $File.FullName "3 folder"
}
}
}
</code>
Now this script gets the files moved and works but its a Powershell script and its running 24/7 365 days a year sometimes the script had stopped sometimes the script has been messed with its just not reliable enough.
So i want to turn it into a application via Visual studio..
Is it possible? remember i have never used Visual Studio before (Been trying it for a few hours learnt some basics)
Has anyone done anything similar to this before/ is there any guide anyone can think of that would suit my needs more?
Im looking for the application to have the following
A status screen ie what files it has found and where it has moved them to.
A setting option to be able to set.. amount of filter string/save paths... change source & export/archive paths etc
Can anyone point me in the right direction? being new i don't know what to search for to get guides on my needs
Cheers
Continue reading...