Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Feb 2014
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Recently modified files script

    Hello All!

    This is my first post here, and it is a pleasure to have access to a community with knowledge about windows scripting. I am a musician and Computer Science student, and I have minimal knowledge of Unix shell scripts, but I have no experience with windows scripts.

    Here's my situation. I have a large folder with 100's of sub folders, each representing a single song I am working on. What I would like my script to do is create links to the last 10 or so modified sub folders. In this way, I could open a folder on, say, my desktop, and have a sort of 'recent files' list of songs I have been working on.

    Any help and advice is appreciated.

    Thank you,
    Codemaster

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Codemaster,

    Welcome to the Lounge as a new poster!

    You don't really need a script for this if your are using Windows Vista or later just use the advanced search capabilities of File Explorer.

    In the search box enter the terms: datemodified:this week kind:=music

    Another possibility since you state folders: datemodified:this week kind:=folder
    Here's a sample output using this one (I downloaded some books and a program today)
    advsearch.JPG
    Please note the selections on the ribbon for "All subfolders" and make sure to select the folder/drive containing all your music folders before doing the search.

    HTH :Cheers:
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. The Following User Says Thank You to RetiredGeek For This Useful Post:

    Codemaster (2014-02-26)

  4. #3
    New Lounger
    Join Date
    Feb 2014
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    RetiredGeek,

    Thanks for the reply! You have a valid point; that seems like a good way to find the most recently modified files. Perhaps for the sake of utter ease of use, and for the sake of my education, how would I go about writing a script to accomplish a similar display of recently modified files?

    Here is some pseudo code:

    1) Delete all files from LINKS directory
    2) Find the 10 most recent folders in SONGS directory
    3) Create links to all 10 in LINKS directory

    I'm not sure where to start writing this in bat or windows script. Advice is appreciated!

    Thanks,
    Codemaster

  5. #4
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Codemaster,

    Ok, here's some PowerShell that will do the trick.
    Code:
    <# +---------------------------------------------+
       | Program Name : NewestfilesCreateShortcut.ps1|
       | Programmed by: RetiredGeek                  |
       | Created      : 02/26/2014                   |
       | Last Update  : 02/26/2014                   |
       | Version No.  : 1.0                          |
       +---------------------------------------------+
    
       Notes:  Use the -Directory switch on the Get-ChildItem
               command if you are searching for directories!
               Delete it if searching for files.
    #>
    
    #-- Initialization Variables --
    
    $FileSpec = ""  #-- Empty string if searching for directories!
                    #-- for xls files use .xls
    $LinkCount = 10 #-- Change to the number of Links you desire
    $PathForLinks = "G:\BEKDocs\MyRecent" # <-- Your Dir here!
    $PathForFiles = "G:\BEKDocs"  # <-- Files to link to top location
    
    #-- End Initialization Variables --
    
    $ExtLength = $FileSpec.Length
    $EndDate = (Get-Date).ToShortDateString()
    
    #-- Remove existing links --
    Remove-Item "$PathForLinks\*.lnk" -recurse
    
    #-- Check for the last 10 days - change as desired --
    $StartDate = (Get-Date).AddDays(-10).toshortdatestring() 
    
    #Processing utilizes the Pipe | to pass results along
    
    #-- Add/Delete -Directory switch as approriate!
    
    Get-ChildItem "$PathForFiles\$FileSpec" -Recurse -Directory  | `
        Where-Object{$_.LastWriteTime -ge $StartDate -AND `
                     $_.LastWriteTime -le $EndDate} | `
        Sort-Object $_.LastWriteTime -Descending | `
        Select -First $LinkCount | `   
        ForEach-Object {
           $ShortName = $_.Name.Substring(0,$_.Name.Length-$ExtLength)
           $WshShell = New-Object -comObject WScript.Shell
           $Shortcut = $WshShell.CreateShortcut("$PathForLinks\$ShortName.lnk")
           $Shortcut.TargetPath = $_.FullName
           $Shortcut.Save() 
        }
    Created Shortcuts.JPG
    The Explorer pic above shows the folders containing a bunch of books I downloaded from the Gutenberg Project.

    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  6. #5
    New Lounger
    Join Date
    Feb 2014
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you RetiredGeek!

    It was very kind of you to go to the trouble, and the script works beautifully. Exactly what I was looking for. What's more, after reading a couple of pages of a PowerShell tutorial the script is beginning to make sense to me. So you've given me a fish, and began to teach me how to fish both, as it were.

    Thanks again for your time and effort, my friend.


    Codemaster

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •