[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 489
  • Last Modified:

Search folders and subfolders and save file as JPG

Hi all,

Just got the assaignment to write a JavaScript the searches through a folder and his subfolders for a PSD file. When it finds one it needs to Save it as a JPG.

Is this possible and how to start with it? Haven't got a clue about JavaScript :( It will be good in VB script too it that is easier...

Grts
0
Pit76
Asked:
Pit76
  • 5
  • 2
  • 2
2 Solutions
 
HonorGodCommented:
That is going to be difficult, especially using any browser other than IE.
Only IE has ActiveX support that allows, or provides support for fileIO from JavaScript.

Most JavaScript implementations don't want scripts accessing the file system for security reasons.
0
 
Pit76Author Commented:
Is this possible in C#, to write a small app to perform this.

I guess I need to open a found .PSD file with PhotoShop and then save it as a JPG file.
How would I start with this? How to iterate through a folder and his subfolders?

Grts
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
MrJesse34Commented:
Its easy, just use the FileInfo and DirectoryInfo objects.  Do foreach statements as well.

Like this:

                    System.IO.DirectoryInfo thisInfo = new System.IO.DirectoryInfo(@"C:\pathname\");
                    foreach (System.IO.FileInfo thisFile in thisInfo.GetFiles())
                    {
                        if (thisFile.Extension.ToUpper() == "PSD")
                        {
                            //DO SOMETHING
                        }
                    }
                   
0
 
HonorGodCommented:
That's what the multi-part article uses...
0
 
MrJesse34Commented:
You don't need to open with photoshop, you can just save with a different extension.
0
 
Pit76Author Commented:
How can I save it with anonther extension? Will the file still work then cos  I tried just to rename it but that doesn't work, thet file can't open as a jpg then.

About the recursive function, does it search a folders su and sub sub folders too?

Never have done anything like this before..

Grts
0
 
HonorGodCommented:
A recursive function will call itself.

Say you have a directory, and you list the contents.
The contents will be files, and possibly more directories.
The routine used to list a directory contents, can be used recursively to process any directories that are encountered.

Does this make sense?

Sorry, I don't have answers for the other questions.
0
 
HonorGodCommented:
Thanks for the grade & points.

Good luck & have a great day
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 5
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now