title: Photoshop scripting, resize if image width is greater than X
body: <p>I'm very new to Photoshop scripting, so please bear with me.</p>
  
  <p>So far I have the below script, but I keep getting an error that my doc object reference is invalid. Can anyone help me properly assign my documents so I can work with them in my conditional statement? </p>
  
  <p>Also need help saving the document with the same file name and extension as it already has, ie even if the filename is horribly formatted like "horrible spaces.JPEG"</p>
  
  <p>THANK YOU!</p>
  
  <pre><code> var inputFolder = Folder.selectDialog("Select a folder to process");
  
   var fileList = inputFolder.getFiles("*.*"); //Use whatever extension you want or no extension to select all files
  
   for(var i=0; i&lt;fileList.length; i++) {
  
   if (fileList[i] instanceof File &amp;&amp; fileList[i].hidden == false) {
      // get a reference to the new document
      var doc = open(fileList[i])
   }    
  
  // do the resizing.  if the width of the document is already less than 500, then don't do anything. Otherwise resize too 500 wide, keep the aspect ratio, and change the resampling.
  if (doc.width &lt; "500px") {
      // don't do anything
  }
  else {
      doc.resizeImage(UnitValue(500,"px"),null,null,ResampleMethod.BICUBIC);
  }
  
      app.activeDocument.close();
  </code></pre>
  
  <p>}</p>