I had a program work on some images of mine and it returned them to my directory. funny thing, they're now all png images instead of gif.
At first i thought it was simple renaming, but I tested with php using createimagefrompng(), which will throw an error if the image is not a valid png file. No errors were returned.
Wheter or not this gives me a 100% accurate result isn't the issue here, the issue is that I want to rename all those files in a similar way.
Now while I could write a php file to do this for me, I'm wondering how I could do the following in batch or c# or java.
All these files still contain the string ".gif", and I want to remove that. In php it would be as simple as using a foreach-loop, reading the file, using str_replace and then destroying the old one and writing the new one.
I'm kinda stuck as to how I would do this in batch, c# or java, can someone help me here?
Also, I am running windows Vista and I have Powershell 1.0 installed.
Solution 1 - C#:
var files = Directory.GetFiles(@"C:\Downloads\Temp\test\");
foreach (var file in files)
{
if(file.Contains(".gif"))
{
string testing = string.Format("{0}.png", Path.GetFileNameWithoutExtension(file.Replace(".gif", "")));
File.Move(file, @"C:\Downloads\Temp\test\"+testing);
}
}