473,320 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

setting file attribute

Hi there. Im a new member here in the forum.

I've got a question to ask.

How do I set the file attribute of a file using C++ coding?
Is there any function when called that will return the state of the file, as in 'hidden', 'archive' and all the file attributes?
Apr 2 '07 #1
4 8304
hi, not sure if this will help but it tried it and it worked for me.

cout<< system("attrib c:/test.txt") << endl;

assuming that you have a file called test.txt in the root of your c drive.
also to modify the attributes open a dos window and type 'attrib /?' with out quotes and it will give you the switches to modify the attributes.

Bruce
Apr 2 '07 #2
Hi there. What I meant was to set the attribute of a file using C++ coding. In other words, I would like to create a file using C++ coding and then set the file attribute to be 'hidden' (for example) so that when I go into the directory, i do not see hidden files.
Apr 7 '07 #3
weaknessforcats
9,208 Expert Mod 8TB
This has nothing to do with C++.

This is an operating system setting. Research your system calls.
Apr 7 '07 #4
Yes, C++ can do the trick. If you were paying attention to what Bruce Mac said, typing “attrib /?” without the quotes on a dos window will give you the possible switches for modifying the file attributes. Thus, after creating an output file (e.g)
ofstream out_stream("test.txt");
Follow it with this line:
system("attrib +h test.txt"); //Set the hidden attribute for test.txt
Or if you want, you can also add the “system” attribute:
system("attrib +h +s test.txt");

Note: test.txt is on the same folder with the executable. You can replace it with the absolute path of the file you are concerned with.

I hope this works for you.
Dec 1 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: user | last post by:
I have gotten properties to respond correctly, but when I try to do it in __init__: class foo: def getter(self): return "hello" def __init__(self):
4
by: G. Richard Bellamy | last post by:
I'm trying to unset the Encrypted attribute on all the files in a path. The attribute is not getting set. What am I doing wrong? Perhaps there's another newsgroup I can send this to? Here's...
2
by: Jim Witte | last post by:
Hi, How do I set a file input element? If it's a text input, I can set the value property. But this doesn't work with file inputs. And no, I can't change it - I'm writing a script to...
7
by: Joey C. | last post by:
Hello, I'm designing a small "briefcase" program that will allow me to quickly upload, download, and delete files in a briefcase. The only real things that I have left to do are to design a...
0
by: Ron James | last post by:
I'm developing a GUI application in C#. I have a schema file (.XSD) and am able to serialize and deserialize the applications data using the schema file to an .XML file. (I'm using xsd.exe to...
3
by: Patrick | last post by:
I am dynamically creating TextArea and drop-down lists in ASP.NET using something like HtmlTextArea eachTextArea = new HtmlTextArea(); I tried to set the "name" of these TextAreas, etc. (e.g....
7
by: Jazz | last post by:
Hello, I am using VSNet 2003 and I am trying to programmatically detect if debug attribute in the compilation tag is true or false. How can I do this ? Thanks, Jazz
1
by: Amit Bansal \(MCT, MCSD.NET\) | last post by:
the msdn documentation says that if we can do application level binding by specifying the masterpagefile attribute in web.config, so that all the pages in the application are bound to a master...
3
by: 7stud | last post by:
"When you bind (on either a class or an instance) an attribute whose name is not special...you affect only the __dict__ entry for the attribute(in the class or instance, respectively)." In light...
43
eof
by: braver | last post by:
I'd like to check, for a filehandle f, that EOF has been reached on it. What's the way to do it? I don't want to try/except on EOF, I want to check, after I read a line, that now we're in the EOF...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.