0

os.listdir() is giving me list of the current folder's files. But I also get, in addition to the ordinary files, this:

.zenmap     DIR
Anaconda2     DIR
AndroidStudioProjects     DIR
AppData     DIR
Contacts     DIR
Desktop     DIR
Documents     DIR
Downloads     DIR
Favorites     DIR
IntelGraphicsProfiles     DIR
Links     DIR
Music     DIR
NTUSER     FILE           6815744 Bytes
ntuser.dat     FILE           327680 Bytes
ntuser.dat     FILE           1744896 Bytes
NTUSER.DAT{9d027246-75b9-11e6-86ab-da51f06118f7}.TxR.0     FILE           1048576 Bytes
NTUSER.DAT{9d027246-75b9-11e6-86ab-da51f06118f7}.TxR.1     FILE           1048576 Bytes
NTUSER.DAT{9d027246-75b9-11e6-86ab-da51f06118f7}.TxR.2     FILE           1048576 Bytes
NTUSER.DAT{9d027246-75b9-11e6-86ab-da51f06118f7}.TxR     FILE           65536 Bytes
NTUSER.DAT{9d027247-75b9-11e6-86ab-da51f06118f7}.TM     FILE           65536 Bytes
NTUSER.DAT{9d027247-75b9-11e6-86ab-da51f06118f7}.TMContainer00000000000000000001     FILE           524288 Bytes
NTUSER.DAT{9d027247-75b9-11e6-86ab-da51f06118f7}.TMContainer00000000000000000002     FILE           524288 Bytes
NTUSER.DAT{dd612578-7782-11e6-b4b2-b01041a7b403}.TxR.0     FILE           1048576 Bytes
NTUSER.DAT{dd612578-7782-11e6-b4b2-b01041a7b403}.TxR.1     FILE           1048576 Bytes
NTUSER.DAT{dd612578-7782-11e6-b4b2-b01041a7b403}.TxR.2     FILE           1048576 Bytes
NTUSER.DAT{dd612578-7782-11e6-b4b2-b01041a7b403}.TxR     FILE           65536 Bytes
NTUSER.DAT{dd612579-7782-11e6-b4b2-b01041a7b403}.TM     FILE           65536 Bytes
NTUSER.DAT{dd612579-7782-11e6-b4b2-b01041a7b403}.TMContainer00000000000000000001     FILE           524288 Bytes
NTUSER.DAT{dd612579-7782-11e6-b4b2-b01041a7b403}.TMContainer00000000000000000002     FILE           524288 Bytes
ntuser     FILE           20 Bytes
OneDrive     DIR
Pictures     DIR
PycharmProjects     DIR

As you can see, I have some folders and files, and also weird files that don't really exist in the folder (they exist, but are invisible).

How can I show only the regular files? (I tried to use stat.S_ISREG already, and the rusults wasn't what I need.)

EDIT:

For example, this file:

NTUSER.DAT{dd612579-7782-11e6-b4b2-b01041a7b403}.TMContainer00000000000000000002

When I'm trying to search for that in my computer - it's like it doesn't exist, there is no match for that file name. (also the 'ntuser.dat' etc...)

martineau
  • 119,623
  • 25
  • 170
  • 301
rgb rgber
  • 1
  • 1
  • Can your code identify the invisible files? If so, then just take them out. – Scott Hunter Sep 21 '16 at 15:11
  • What do you mean by 'invisible'? Not visible in Windows Explorer? They are certainly visible to `os.listdir()`, which is just a system call. – Martijn Pieters Sep 21 '16 at 15:13
  • And can you tell us which ones of those files you see are the 'weird files'? I don't normally use Windows, for all I know the `NTUSER.DAT{...}` files are perfectly regular files. – Martijn Pieters Sep 21 '16 at 15:14
  • FYI: I marked as dupe. One of the answers in the other question addresses Windows. – nneonneo Sep 21 '16 at 15:15
  • @MartijnPieters: Some files on Windows have the HIDDEN and/or SYSTEM file attribute flags set, which makes them invisible by default in Windows Explorer. – nneonneo Sep 21 '16 at 15:15
  • @nneonneo: sure, but *which ones*? – Martijn Pieters Sep 21 '16 at 15:16
  • @MartijnPieters: Per http://stackoverflow.com/a/14063074/1204143, `win32api.GetFileAttributes` can be used to get the file attributes. It's Windows-specific, but IIRC `win32api` is present on all Windows builds of Python. – nneonneo Sep 21 '16 at 15:17
  • @nneonneo: sure, I know, I'm trying to help the OP improve their question.. – Martijn Pieters Sep 21 '16 at 15:18

0 Answers0