Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Script to Delete Alternate Files?

Posted on 2011-05-07
6
Medium Priority
?
318 Views
Last Modified: 2012-05-11
Hello,

Would someone mind creating a Powershell script that will delete alternate files in a directory for me please?

I've been saving timelapse images every 20 seconds (using iSpyConnect) of an extension to my house that is being built. I've then used Quicktime Pro to combine these images into a movie each week, but now I want to combine multiple weeks into one large timelapse movie.

The problem is I have 1000's of images, and even running at 60fps results in a video that is too long. I would therefore like to delete every second OR third file in an automated way rather than manually selecting files myself, which would take ages. :)

For example, I have a directory with images named in numerical order based on the date they were created.

1.jpg
2.jpg
3.jpg
4.jpg
5.jpg
6.jpg
etc...

I would like to delete files named 2, 4, 6, and so on throughout the whole directory, which at the moment contains over 10,000 images! If I find that deletes too many, I would also like the option to delete every third file as well please - 3, 6, 9, etc.

Many thanks in advance for your help.
0
Comment
Question by:jarrah10
  • 4
  • 2
6 Comments
 
LVL 1

Expert Comment

by:99star
ID: 35712258

What you can do is try to write script which takes time of the file including seconds then omit those which you don't want to be in movie like viewing

example 1st image 22:00:00    ( timing in seconds is very important )
               2             22:00:20 ( Omit )
               3             22:00:40
               4             22:01:00 ( Omit )

and so on
0
 
LVL 1

Expert Comment

by:99star
ID: 35712273


You can even write windows shell script or even an batch file
you study some intricacies
0
 
LVL 1

Author Comment

by:jarrah10
ID: 35712462
Unfortunately the seconds timestamp varies considerably - it's every 20 seconds after the capture starts so it could be any time really. :)

I'm open to any way possible to do this on Windows - I just don't have the scripting knowledge to work this out myself.

Thanks.
0
Who's Defending Your Organization from Threats?

Protecting against advanced threats requires an IT dream team – a well-oiled machine of people and solutions working together to defend your organization. Download our resource kit today to learn more about the tools you need to build you IT Dream Team!

 
LVL 1

Author Comment

by:jarrah10
ID: 35712654
Blimey, I somehow managed to figure out this myself with the help from this page: http://www.powershellcommunity.org/Forums/tabid/54/aft/5742/Default.aspx 

Function Odd ([String] $number) {
    $lastChar = $number[$number.length-1]
    $intNumber = $lastChar / 2
    $strNumber = $intNumber.ToString()
    $result = $strNumber.Split(".").length
    switch ($result) {
        1 { return $false } # final character is EVEN
        2 { return $true } # final character if ODD
        default { return $false } # unknown
    }
}

foreach ($file in dir -name) {  
    $num = Odd $file
    #echo "The file $file is $num"
    If ($num -eq $false) {
        #echo "The file $file is EVEN"
        Remove-Item $file
    }
}
0
 
LVL 1

Accepted Solution

by:
jarrah10 earned 0 total points
ID: 35712723
Here's the full working version that has been tested as working.

Function Odd ([String] $number) {
    $lastChar = $number[$number.length-1]
    $intNumber = $lastChar / 2
    $strNumber = $intNumber.ToString()
    $result = $strNumber.Split(".").length
    switch ($result) {
        1 { return $false } # final character is EVEN
        2 { return $true } # final character if ODD
        default { return $false } # unknown
    }
}

dir |% {rename-item $_.fullname -newname $_.basename}

foreach ($file in dir -name) {  
    $num = Odd $file
    If ($num -eq $false) {
        Remove-Item $file
    }
}

dir | Rename-Item -NewName {$_.name + ".jpg"}
0
 
LVL 1

Author Closing Comment

by:jarrah10
ID: 35744732
I managed to figure it out myself.
0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Screencast - Getting to Know the Pipeline

576 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question