473,399 Members | 3,656 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,399 software developers and data experts.

Create text file with the name as System date

Hi,

I want to create a text file with the name as SYSTEM DATE...
for example---28/04/2008:9:11:50.txt
The File name should be allocated dynamically.

Can you provide me some details how to write the code for this..

Plese help me.
Dec 21 '10 #1
9 10621
donbock
2,426 Expert 2GB
The first thing you want to do is confirm that a filename of that form is legal for the operating systems that you intend to run your program on.

Step 1: obtain the system date and time in the desired format.

Step 2: create a file with that filename.

Which step are you having trouble with?
Dec 21 '10 #2
hi,
thanks for the reply.
i cant able to understand how to create a file with the file name.
i tried this code.

#include <time.h>
#include<stdio.h>
#include<sys/types.h>
#include<sys/types.h>
#include<fcntl.h>
int main()
{
char s[30];
int fp;
size_t i;
struct tm tim;
time_t now;
now = time(NULL);
tim = *(localtime(&now));
i = strftime(s,30,"%b %d, %Y; %H:%M:%S\n",&tim);
printf("%s\n",s);
}
output of this is
Dec 21, 2010; 10:30:34

i want to open a file like this :
Dec 21, 2010; 10:30:34.txt

Please give me suggestion regarding this.Is it possible to open a file like this?
Dec 21 '10 #3
johny10151981
1,059 1GB
For Some os it is not possible. as Example Windows. You cannot add : to a file name. Cause it is a special character that separates directory from file name
Dec 21 '10 #4
donbock
2,426 Expert 2GB
I suggest you use strftime format string "%Y-%m-%dT%H-%M-%S.txt". This avoids troublesome characters (such as ":" and space). It also has the added benefit that an alphabetical listing (such as when you list the contents of a directory) appear in chronological order.

It isn't obvious to me why you terminated your format string with newline.

(I'm suggesting a variant of the W3C DTF standard for date/time strings -- replace colons with dashes and omit the time zone designator.)

By the way, you should confirm that the return code from strftime is nonzero.
Dec 21 '10 #5
Hi,
Thanks for your suggestions.I kept the
strftime format string "%Y-%m-%d T%H-%M-%S.txt" and tried.The output is 2010-12-22T10-20-31.txt
but the text file is not opening in the directory.
Dec 22 '10 #6
donbock
2,426 Expert 2GB
How are you trying to open the text file?
Dec 22 '10 #7
I opened a file like this `date +%d-%m-%Y`.txt
I can able to create the file successfully.
Actually i want to append the data from mouse into this file.I got the data from mouse using libusb API and i can print that data.

Please help me how to append the data from mouse into file (20-10-2020.txt).Is it possible to append data into the file if we create a file like this..

Please give me some suggestions regarding this.

thanku
Dec 22 '10 #8
donbock
2,426 Expert 2GB
Please show us the C code that opens the file.
Dec 22 '10 #9
thanks for your suggestions.I can able to open the file.I formatted the fopen incorrectly.Now i got it.
Dec 23 '10 #10

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

Similar topics

3
by: CJA | last post by:
Hi I have a script that will compact an Access MDB and a copy to a new folder. I would it to give each export a unique file name. I can do this with an absolute file reference but I am...
1
by: Mike | last post by:
I'm trying to create a text file and when i compile my code i keep getting invalid token FileInfo t = new FileInfo("test.txt"); StreamWriter Tex =t.CreateText(); Tex.WriteLine("test file");...
0
by: Darin | last post by:
I have a comma-delimited text file that I am reading via a connection string: junk = "Provider=Microsoft.Jet.OLEDB.4.0;" junk &= "Data Source=\inware\data\df;" junk &= "Extended...
4
by: Ernesto | last post by:
Can Python be used to create (and/or open, read, and write) a text file in Windows (if the path is known) ?
3
by: Simon Rigby | last post by:
Hi folks, Excuse if this has been asked before, and by all means just point me at a thread if thats a suitable response. I have a mySql database which I am running various queries against. Can...
3
by: Elavarasi | last post by:
Hi, I would like to know if it is possible to use JavaScript to write to a text file. I tried using FileSystemObject in JavaScript. However, it gives the following error : "Automation server can't...
3
by: selvialagar | last post by:
Hi.............. I need to extract a textfile (.txt) file alone from the application startup path. That is I stored a text file in d:\text\inputfile.txt. The folder contains a text file.but i...
1
by: lily86 | last post by:
hello, i wan to create a web forms using vb.net....i wan to save my text box data to text file and when next time i open my web forms my data still remain there untill i clear the data.....help pls!!
2
by: apank | last post by:
Using VBA, is there a way to transfer text a table or query and have the saved file name be some text followed by today's date (example"newfile.11.17.08.txt"). Also can that file then be winzipped...
9
by: apptech | last post by:
I am writing a small application for my company. There are two text boxes and a submit button. textBox1 is where the information is entered to be write to the text file. TextBox2 is where the the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.