displaying folder directory

This topic contains 0 replies, has 1 voice, and was last updated by Profile photo of Forums Archives Forums Archives 5 years, 4 months ago.

  • Author
    Posts
  • #5606

    by vanhoja at 2013-02-27 11:54:38

    Hello,

    I am completely new to PowerShell, today is my first day even using it. I have written a script that checks 3 shared folder locations for new files and gives a windows prompt if a new file has arrived. Since it is searching 3 different locations and prompting, I am wondering if there is a way to have it give full or even better just the folder file is in. Below is my code:

    $currentFiles = Get-ChildItem \\server1\Queued\, \\server2\Error\, \\Server3\FAILED\
    while(-1){

    $newFiles = Get-ChildItem \\server1\Queued\, \\server2\Error\, \\Server3\FAILED\

    if($newFiles.count -ne $currentFiles.count){
    $currentFiles = $newFiles
    #Write-Host `a
    $a=New-Object -comobject wscript.shell
    $b=$a.popup("File in Queued needs processed",0,"New File in Queued",1)
    }

    Start-Sleep(5)
    }

    by DonJ at 2013-02-27 11:59:11

    "Have it give full or even better just the folder file"

    Sorry, I don't understand what you're asking for. Full what?

    by vanhoja at 2013-02-27 12:47:00

    Sorry, give the full directory path ex. \\server1\folder1\queued or just Queued folder name etc for the folder location that the script finds the new file.

    by DonJ at 2013-02-27 12:56:47

    Sure. You have the files in $NewFiles, just display their FullName property.

    $NewFiles | Select FullName

    Or use Path, I think, if you just want the folder name.

    by vanhoja at 2013-02-27 14:17:09

    Ok, I am trying to figure that part out, I hate to ask but what should the code actually be to have it display in my prompt window with the message about the new file.

    by DonJ at 2013-02-27 16:40:40

    So... looking back, I take it back. That won't work. Your $newfiles contains ALL the files – you're just figuring out if there's something new by looking at the count. If there are a LOT of files (thousands), this may not even work well, or quickly. Either way, you can't pull "just" the new files out of that list that way.

    Look into the Compare-Object command. If you have a list of "existing" files, and then get a list of "current" files, it can show you what's different.

    Rather than storing everything in memory, I'd suggest using a file. Consumes less memory. For example:


    Dir -path C:\Whatever | Export-CliXML c:\Something\existing.xml

    # and then later do this to find differences...
    Compare-Object -reference (Import-CliXML c:\something\existing.xml) -difference (Dir -path c:\whatever)

    The output of Compare-Object is a collection of difference objects. You can parse those and select specific properties of them if you want to display the list, but a popup dialog box isn't going to be a good technique for that. PowerShell wasn't designed to do pretty dialog boxes, unfortunately. I'd consider just displaying the information in the console, and perhaps popping up a dialog that directs someone to look at the console for the complete list.

    by vanhoja at 2013-02-27 20:15:19

    ok, well I wasn't wanting to display the list of files, I got the script to prompt when a new file comes in but it checks 3 different folder locations and it work better if it told us which folder the file is in so we don't have to manually search and then process it.

    by vanhoja at 2013-03-07 20:40:28

    Well I figured out a way around it, I even added gui form prompts and when clicking on the button it will take you to the folder location that has received the file. The code may not be preaty, compiled program calls an exe and 3 script files but it works!

You must be logged in to reply to this topic.