3

I'm using the command "dir" on a directory with 500,000 files. It's been running for 15 minutes now.

Is there any way to speed it up? an alternative command perhaps?

Thanks in advance,

Gil.

GilLevi
  • 2,117
  • 5
  • 22
  • 38

2 Answers2

5

If you just want file names, try files = ls;. As per the help, I believe ls should work on any OS. The reason dir takes so long in your case is that it's calculating the file size, modification date, etc. of each file.

horchler
  • 18,384
  • 4
  • 37
  • 73
3

I know this is an old post, but...

I'd like to point out that if you decide to use the "ls" function (as opposed to "dir") this behaves slightly differently in Unix and Windows operating systems, so be mindful of this.

e.g., consider the following:

a=ls

In Unix, above will produce a 1xM array (of type char) containing the contents of the working directory.

In Windows, it will produce an NxM array (of type char) with the directory's contents, where N is equal to the number of files and directories in the working directory and M is the character-length of the longest file (or directory) name.

"dir" is portable and behaves the same in Unix and Windows FME.

For this reason I've had some slight difficulties porting my MATLAB codes between Windows and Unix in the past (specifically CentOS 6.2).

  • @HeWhoLikesWaffles: Good point. My guess is that this difference dates back to Matlab's old days when pretty much all strings where treated like matrices with extra spaces for padding (not fun). I think that an easy way to convert the output of `ls` on Windows to a form like that on a UNIX system would be: `a = cellstr(ls);` `sprintf('%s\n',a{:})`. This should even work with `ls` on UNIX machines – at least it did on OS X 10.9.4 and the latest Matlab. – horchler Aug 18 '14 at 19:30