By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,679 Members | 1,030 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,679 IT Pros & Developers. It's quick & easy.

hidden attribute on Windows files

P: n/a
rbt
How do I enable the hidden attribute when creating files on Windows
computers? I'd *really* prefer to do from the standard Python installer
(no win32 extensions). Any tips?

Thanks
Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
rbt wrote:
How do I enable the hidden attribute when creating files on Windows
computers? I'd *really* prefer to do from the standard Python installer
(no win32 extensions). Any tips?


You could do

os.system('attrib +h hidethis.txt')

but that only works if hidethis already exists.

--
"Codito ergo sum"
Roel Schroeven
Jul 18 '05 #2

P: n/a
rbt wrote:
How do I enable the hidden attribute when creating files on Windows
computers? I'd *really* prefer to do from the standard Python installer
(no win32 extensions). Any tips?


With pure Python and just the standard installer, you need to invoke
attrib.exe, as

attrib.exe +H <pathname>

Use os.system to invoke that command, make sure you get the quoting
right in case pathname might contain spaces. attrib.exe is located
in the system folder (windows\system32), so it should be on the PATH.

HTH,
Martin
Jul 18 '05 #3

P: n/a

rbt wrote:
How do I enable the hidden attribute when creating files on Windows
computers? I'd *really* prefer to do from the standard Python installer (no win32 extensions). Any tips?

Thanks


Breaking your problem down a bit:
1. How is that done from the command line in Windows?
2. How to execute an os command line from within stock-standard Python?

Which of those parts are you having trouble with?

If you want to help yourself, DON'T read the end of this message ...



=== Warning: spoon-feeding follows ===

[results of "dir" command are trimmed down to the bare essentials]

C:\junk\hidatt>dir
08/03/2005 07:56a <DIR> .
08/03/2005 07:56a <DIR> ..
08/03/2005 07:56a 13 fubar

C:\junk\hidatt>python
Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
import os
r = os.system('attrib +h fubar')
r 0 r = os.system('dir') 08/03/2005 07:56a <DIR> .
08/03/2005 07:56a <DIR> .. r = os.system('attrib -h fubar')
r = os.system('dir') 08/03/2005 07:56a <DIR> .
08/03/2005 07:56a <DIR> ..
08/03/2005 07:56a 13 fubar


Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.