Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Problem with getFiles()

Engaged ,
Nov 12, 2013 Nov 12, 2013

I'm having a problem with getFiles()  - changing it from a user supplied path with selectDialog to a hard coded path. I know there are bug issues with early versions of CS and getFiles, but I can't see where I'm going wrong with:

// just get files

var sourceFolder = "C:\\temp\\json";

if (sourceFolder != null)

{

  var fileList = sourceFolder.getFiles();

}

Thank you.

TOPICS
Actions and scripting
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guru , Nov 12, 2013 Nov 12, 2013

Yes you can use either forward or back slashes. That wasn't the reason for your problems with getFiles(). The problem is you were trying to use a folder method on a string object.

// just get files var sourceFolder = "C:\\temp\\json";// this is a string objectif (sourceFolder != null)// it will never be null because it was just defined on th line above. Did you mean sourceFolder.exists?{  //var fileList = sourceFolder.getFiles();// strings do not have a getFiles method.

  var fileList = Folder(sou

...
Translate
Adobe
Advisor ,
Nov 12, 2013 Nov 12, 2013

Try

var sourceFolder = Folder("C:
temp
json");

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 12, 2013 Nov 12, 2013

There are two ways to list a path, one as X shows, the other is using "/" and no colon.  It looks like your main issue is the double backslashes,

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 12, 2013 Nov 12, 2013

var sourceFolder = Folder("C:

temp

json");

That just gets me: Error 4: Unterminated string constant.

ha ha! I've just seen what's gone on. The slashes have been turned into new lines by the web pixies. All appease the web pixies! Feed them sour milk, diet donuts and slashes! Ahem....

It should have read

var sourceFolder = Folder("C:/temp/json");

also works with back slashes

var sourceFolder = Folder("C:\\temp\\json"); // use back slashes

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Nov 12, 2013 Nov 12, 2013
LATEST

Yes you can use either forward or back slashes. That wasn't the reason for your problems with getFiles(). The problem is you were trying to use a folder method on a string object.

// just get files var sourceFolder = "C:\\temp\\json";// this is a string objectif (sourceFolder != null)// it will never be null because it was just defined on th line above. Did you mean sourceFolder.exists?{  //var fileList = sourceFolder.getFiles();// strings do not have a getFiles method.

  var fileList = Folder(sourceFolder).getFiles();}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines