Hi all,
How will you list all ONLY the files in the entire drive?
for example,
I want to print the file path of all files in it as well as the files in the folder and its subdirs?
ONLY THE FILE PATH!!!
Thankyou everyone in advance!!! :)
it can be solved without programming.
1. open cmd
2. write following line
dir d: /a /s /b > d:/files_path.txt
3. now, d:/files_path.txt include paths of all files.
meaning
d:
search d drive
/a
show all files
/s
search subdirectory, too
/b
bare format
> d:/files_path.txt
save result into d:/files_path.txt
Or something like that, I didn't try this code but the basic idea is there. Keep in mind that for the ANSI version of FindFirstFile() the length is limited to MAX_PATH, so more about this in the link below.
@ Duoas: It looks like it should be faster, it would be a few less push\pull instructions. I've always coded for readability and relied on the compilers ability to optimize for speed. Although I honestly don't know the limits to it's abilities in this regard.
I don't think this is about speed, I think this is about meaning. Duoas is suggesting that dwFilAddtributes is a flag variable which, in the presence of more than once flag, will not be equal to any flag (and thus the inequality comparison will be true even for directories).
@ LB: dwFileAttributes is a DWORD, which is an unsigned int so "!=" should be fine. I use this code (actually the inverse of it) in production and it's never given me any trouble.
@OP: My sample code doesn't have any error checking, I would start by adding that to make sure that FindFirstFile() returns a valid HANDLE.
@ LB: dwFileAttributes is a DWORD, which is an unsigned int so "!=" should be fine. I use this code (actually the inverse of it) in production and it's never given me any trouble.
Pretty sure with flag-based variables it doesn't work like that.
@ LB: I figured out what he was saying, and you were close with that example you deleted. Duoas was pointing out that a file\folder can have a combination of attributes and my code doesn't account for that. For example if a folder was hidden then it's dwFileAttribues value would be at least 18 (FILE_ATTRIBUTE_DIRECTORY + FILE_ATTRIBUTE_HIDDEN) and my code would over look it.
I don't think this is about speed, I think this is about meaning. Duoas is suggesting that dwFilAddtributes is a flag variable which, in the presence of more than once flag, will not be equal to any flag (and thus the inequality comparison will be true even for directories).
@ LB: Yes you were right, I'm not really paying enough attention to any particular thing right now so don't take it personally. I should be focusing on the 13 laptops that are 75 miles away from me and keep going to sleep while I'm trying to update Java on them. But because I'm a terrible employee I'm here instead because dividing my attention like this keeps me calm for some reason.
@ OP: How's that error reporting look? Did you find out what went wrong?