• Quick note - the problem with Youtube videos not embedding on the forum appears to have been fixed, thanks to ZiprHead. If you do still see problems let me know.

Programming / help needed to get started

Another issue is whether it has to be self-contained, or whether you can pretty much install any runtimes/scripting languages you like on the target machine?

Visual C# 2008 Express is free from Microsoft (it's a somewhat cut-down version of Visual Studio) and will make standalone executables that only depend on whatever version of .NET you target. It's a good place to start programming. It is also very GUI-oriented which means that you can lay out your entire user interface in a WYSIWYG editor and then just pick the events for the various controls that you want to use from a list, and then write the C# code that makes it do something.
 
Visual C# 2008 Express is free from Microsoft (it's a somewhat cut-down version of Visual Studio) and will make standalone executables that only depend on whatever version of .NET you target. It's a good place to start programming. It is also very GUI-oriented which means that you can lay out your entire user interface in a WYSIWYG editor and then just pick the events for the various controls that you want to use from a list, and then write the C# code that makes it do something.

First, let me say that C# is my language-of-choice. However, C# is strictly object-oriented, and if the OP isn't familiar with OOP, it can a painful learning curve for someone working alone. Objects are optional in a lot of the other languages (C++, Python, VB, Delphi, etc).

On the other other hand, it's going to be tough to write a WinAPI GUI without some understanding of OOP.
 
Yeah, you're probably right. It might be too much unless you have a real interest in investing time in learning it.

Looking at the AutoIt website though, it certainly looks like it should be able to do everything you have specified, including making GUIs. I mean, all you seem to want to do is enumerate through a list of folders/files and compare each item to a certain pattern and potentially rename it. AutoIt even claims to have COM support, which means you can just create an Excel.Application object and fill it with your data. Instant Excel output with very little work.

The only issue, I suppose, is finding a way to verify the integrity of images. I'm sure utilities and libraries to do that can be found with a little Google searching. Just attempting to load them with some image viewing API likely won't be enough since corrupted images can often still be loaded.
 
Another issue is whether it has to be self-contained, or whether you can pretty much install any runtimes/scripting languages you like on the target machine?

Self-contained would be better, but if I got it working for me that would be a big step forward, too.

Visual C# 2008 Express is free from Microsoft (it's a somewhat cut-down version of Visual Studio) and will make standalone executables that only depend on whatever version of .NET you target. It's a good place to start programming. It is also very GUI-oriented which means that you can lay out your entire user interface in a WYSIWYG editor and then just pick the events for the various controls that you want to use from a list, and then write the C# code that makes it do something.

That sounds very good.

Yeah, you're probably right. It might be too much unless you have a real interest in investing time in learning it.

They did try to make me understand OOP back in school. I might be able to remember a bit of it, even. As the tasks wouldn't be overly complex it might not be too difficult to get that part worked out, also.

Looking at the AutoIt website though, it certainly looks like it should be able to do everything you have specified, including making GUIs. I mean, all you seem to want to do is enumerate through a list of folders/files and compare each item to a certain pattern and potentially rename it.

Mostly, yes. But I'm sure that I'll find many other interesting things that I want to happen once i got those first steps figured out ...

AutoIt even claims to have COM support, which means you can just create an Excel.Application object and fill it with your data. Instant Excel output with very little work.

Yes, I suspect the task will not be impossible or overly difficult - just annoyingly cumbersome whichever the language.

The only issue, I suppose, is finding a way to verify the integrity of images. I'm sure utilities and libraries to do that can be found with a little Google searching. Just attempting to load them with some image viewing API likely won't be enough since corrupted images can often still be loaded.

I am confident that I can figure out stuff like that if I have to. Of course, just using existing methods would be a lot easier.
 
If I read this correctly you simply need to determine if the contents of a file is an image or not, and possibly correct the file name/extension if it is in error?

I bought a book several years ago when I had to write a program to do image format conversion. It's actualy fairly simple to indentify the image type by the contents. Every image format I looked at back then simply starts the file with a particual string to identify it as an image of that type.

Determining if the rest of the file is arranged properly for that image type is another issue that I doubt you are concerned with. It seems you simply want to find any file not named as an image that actualy has an image within.

ie: file abc.jpg has been renamed abc.bak and you want your utility to recognize abc.bak as a jpg and rename it

Is that what you are looking to do? I could probably give you the file spec for whatever image types you want to be able to recognize, if you like.
 
If I read this correctly you simply need to determine if the contents of a file is an image or not, and possibly correct the file name/extension if it is in error?

I bought a book several years ago when I had to write a program to do image format conversion. It's actualy fairly simple to indentify the image type by the contents. Every image format I looked at back then simply starts the file with a particual string to identify it as an image of that type.

Determining if the rest of the file is arranged properly for that image type is another issue that I doubt you are concerned with. It seems you simply want to find any file not named as an image that actualy has an image within.

ie: file abc.jpg has been renamed abc.bak and you want your utility to recognize abc.bak as a jpg and rename it

Is that what you are looking to do? I could probably give you the file spec for whatever image types you want to be able to recognize, if you like.

If it's as simple as that: the Unix/Linux command 'file' is your friend.
The file /usr/share/file/magic (on my Linux box) contains the patterns with which it recognizes the various file types.

Is the 'file' command part of the Unix compatibility package for Windows? There is such a package, don't know the exact name. I think it's a free download from the Microsoft site, and that it's the former MKS toolkit.

ETA: Not MKS, but the InterixWP package is provided for free by Microsoft. See the wiki page for links to MS' site.

If it's really as simple as Molinaro interprets, I code this up in half an hour or less in a Unix shell script...
 
Last edited:
Is the 'file' command part of the Unix compatibility package for Windows? There is such a package, don't know the exact name.
Microsoft's Unix utilities exist in an isolated subsystem. They are not Win32 command line utilities.
 
Your problem sounds like it language independent. Any language that has an API for dealing with file systems can do it, I suspect. (and COM or .NET support, for writing out an Excel file, though a CSV file might suffice, if you can't do that.)

So, go with a language that is easy to learn. Like VB or C#. I think someone mentioned the Express editions of these. C++ is not terribly convenient, unless you're already good at it.

If you are checking files for a particular pattern, you might be able to utilize regular expressions. Though, that idea tends to have a bit of a learning curve to it.


ETA: Ah, I see you are also checking the integrity of certain files. I might actually have tools for many of those file types at work! In general, the more widely used a language is, the more such tools will be available.
 
Last edited:
The only issue, I suppose, is finding a way to verify the integrity of images. I'm sure utilities and libraries to do that can be found with a little Google searching. Just attempting to load them with some image viewing API likely won't be enough since corrupted images can often still be loaded.

I already gave a solution for this. Use the identify command-line utility that comes with ImageMagick. It is available for the Windows platform.
 
If I read this correctly you simply need to determine if the contents of a file is an image or not, and possibly correct the file name/extension if it is in error?

It's a little more, since I need to check the file beyond its extension to ensure that something that's called like an image-file actually is one, and that it didn't get corrupted somewhere. (Like a simple file-copy action that just lost me a day of work ...)

I bought a book several years ago when I had to write a program to do image format conversion. It's actualy fairly simple to indentify the image type by the contents. Every image format I looked at back then simply starts the file with a particual string to identify it as an image of that type.

It seems to me that some of the formats are a little more flexible, though. :) But that is precisely what I was getting at.

Determining if the rest of the file is arranged properly for that image type is another issue that I doubt you are concerned with. It seems you simply want to find any file not named as an image that actualy has an image within.

No, I want to make sure that the image file "works", i.e. can be opened and displayed as an image.

ie: file abc.jpg has been renamed abc.bak and you want your utility to recognize abc.bak as a jpg and rename it

Is that what you are looking to do? I could probably give you the file spec for whatever image types you want to be able to recognize, if you like.

No, I want to look at file 127-18093-0005.jpg , make sure that the name prefix corresponds to the folder name, that the last digits form a simple, consecutive counter and that if I double click the file I'll get to see a picture instead of an error message from my default-viewer.



Your problem sounds like it language independent. Any language that has an API for dealing with file systems can do it, I suspect. (and COM or .NET support, for writing out an Excel file, though a CSV file might suffice, if you can't do that.)

So, go with a language that is easy to learn. Like VB or C#. I think someone mentioned the Express editions of these. C++ is not terribly convenient, unless you're already good at it.

I'm not. My main issue was that I thought I could gain speed by chosing the appropriate language. Now I know better and thanks to you guys I know what a lot of my other issues ought to be, too.

If you are checking files for a particular pattern, you might be able to utilize regular expressions. Though, that idea tends to have a bit of a learning curve to it.

The file names will be far simpler than that, and I fear that the file headers will be a lot more complicated in most cases.

ETA: Ah, I see you are also checking the integrity of certain files. I might actually have tools for many of those file types at work! In general, the more widely used a language is, the more such tools will be available.

I suppose so, yes.
 
The *nix file command is available for the Windows command line from gnuwin32.sourceforge.net.

As others have commented, though, the ImageMagick identify command-line tool will also work, and is probably a better choice if you're only working with image files (JPEG, GIF, BMP, etc.). ImageMagick is also good for transforming images from the command line (convert types, resize, crop, and so forth).

ETA: gnuwin32 site; page for file

ETA 2: ImageMagick site; identify details
 
Last edited:
I already gave a solution for this. Use the identify command-line utility that comes with ImageMagick. It is available for the Windows platform.
Yeah I saw it, but it may not be the best choice. Launching a new process and interpreting its output is a very expensive operation, especially if you will be scanning thousands of images. I haven't looked at what the identify command does, but if it basically just calls a few functions from the ImageMagick library, I would prefer to just load the library directly and call the same stuff myself.

I'm not. My main issue was that I thought I could gain speed by chosing the appropriate language. Now I know better and thanks to you guys I know what a lot of my other issues ought to be, too.
Well, you can gain quite a lot of speed. Like the example above, where calling a library function is a lot faster than calling an external utility.

There has to be a balance between the amount of work it takes to implement it and what one gets in return. A utility that you're going to run very rarely and that has no performance requirements is probably best implemented as a quick and simple script using as many premade tools as possible.
 
Well, you can gain quite a lot of speed. Like the example above, where calling a library function is a lot faster than calling an external utility.

There has to be a balance between the amount of work it takes to implement it and what one gets in return. A utility that you're going to run very rarely and that has no performance requirements is probably best implemented as a quick and simple script using as many premade tools as possible.

I need to do this all the time, and it's slow and cumbersome the way it is now. (Else I'd simply have tried to run a script on top of the tool I currently have ...) So speed is an issue - the question just is am I clever enough to find out what I need to do to optimize it. And, of course, it's a question of whether the gain will be noticeable over everything else that is going on.

I've used scripts in the past do some simple image checks (rotate all images to landscape, e.g., something that nobody on the face of the earth seems to have needed ever before ... ) so that at least works. I have no way of measuring the impact of various different methods, though - I was glad to even get it to work.

If you're worried about repeatedly launching processes, then look into the various ImageMagick APIs, most notably PerlMagick. There's also a C interface (MagickWand), a C++ interface (Magick++), and many others: see http://www.imagemagick.org/script/api.php

Wow. Thanks.
 
I would definitely give C# a try, despite the somewhat higher learning curve over simple scripts.

Things like rotating images is simple enough. You could use the included Image class, load the image into it, check if it's landscape and if not, call the .RotateFlip method on it, then save it to disk. Maybe back up the original since there will always be some quality loss (if it's a lossy format.)
 
I put together a simple .NET 2.0 sample in C# that shows how one might do basic file scanning.

When you click Scan, it pops up a folder selection dialog, then it spawns a BackgroundWorker (an easy to use thread class) which then scans through all the files in the selected folder and attempts to load them with the Image class. It also does some basic checking to see if the extension is correct, whether it's landscape, and it also compares the file name with a simple regular expression (which just checks the file extension.)

You can download it at http://home.no.net/jsiv/ImageScan.zip if you want to have a look at what you would be facing. There's a compiled version in ImageScan\bin\Release.

(It might seem like a fair bit of code, but it's mostly auto-generated by Visual Studio.)
 
Last edited:
I would definitely give C# a try, despite the somewhat higher learning curve over simple scripts.

Things like rotating images is simple enough. You could use the included Image class, load the image into it, check if it's landscape and if not, call the .RotateFlip method on it, then save it to disk. Maybe back up the original since there will always be some quality loss (if it's a lossy format.)

I've been using something called jpegtrans (I think) for that sort of thing, it allows lossless JPEG transformation and manipulation of the images.
 

Back
Top Bottom