Search code examples
windowscmdforfiles

W10 CMD forfiles


Since I had a task where I have to copy recursively files of a nested directory for work, i discovered the forfiles-function in windows cmd.

It worked properly and now I wonder how does the function distinguish between a file and a directory?

If every file had a file extension like .jpg .png .xls or something like that, I could understand it, but some of my files came without extensions, but it still did its job.

As I'm used to linux, I tried to google the sourcecode, but windows applications aren't opensource, so if anybody can explain me, how does it work, it would be very interesting to know.

PS: why does this got downvoted? its a general question


Solution

  • The command will eventually call the Windows FindFirstFile/FindNextFile functions. Those return a WIN32_FIND_DATA structure which may contain a FILE_ATTRIBUTE_DIRECTORY flag. If that flag is not set, it's a file.