473,405 Members | 2,141 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,405 software developers and data experts.

file name

I have an app were i'm creating log files, but i want to give the log files
a distinctative names such as
Error_1/1/200512:30AM.log

how can I get the date/time in the file name? I tried this and it errors
out on me.

string strFileName = \\servername\\Error + "_" + System.DateTime.Now +
".log";

and it breaks, how can i get this working?
Nov 17 '05 #1
3 1454
You cannot have such special characters in file names like "/, :, and
others". Just try renaming a file in Windows Explorer with any of these and
you will see that it won't. You will need to replace those characters with
another, maybe an underscore.

Alex

"microsoft.news.com" <CSharpCoder> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
I have an app were i'm creating log files, but i want to give the log files
a distinctative names such as
Error_1/1/200512:30AM.log

how can I get the date/time in the file name? I tried this and it errors
out on me.

string strFileName = \\servername\\Error + "_" + System.DateTime.Now +
".log";

and it breaks, how can i get this working?

Nov 17 '05 #2
You're missing the conversion of DateTime to String

It should read:

string strFileName = "\\servername\\Error" + "_" +
System.DateTime.Now.ToString() + ".log"

"microsoft.news.com" <CSharpCoder> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
I have an app were i'm creating log files, but i want to give the log files
a distinctative names such as
Error_1/1/200512:30AM.log

how can I get the date/time in the file name? I tried this and it errors
out on me.

string strFileName = \\servername\\Error + "_" + System.DateTime.Now +
".log";

and it breaks, how can i get this working?

Nov 17 '05 #3
Dan
You need to specify the format that the DateTime converts to to make it
file system friendly.

string strFileName =
"Error_" + System.DateTime.Now.ToString("yyyyMMddHHmm") + ".log

Should give:
Error_200504131319.log
....when generated @ 1:19pm today

HTH,
Dan

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Fu Bo Xia | last post by:
the java.lang.Object.forName method takes a java class name and returns a Class object associated with that class. eg. Class myClass = Object.forName("java.lang.String"); by if i only know the...
21
by: ryanmhuc | last post by:
I know the subject might be confusing. I am no beginner with javascript but I haven't been able to figure out how to get the javascript file name from code inside the file. So you have an HTML...
3
by: Wayne Aprato | last post by:
I am using code kindly provided by the Access Web to capture a file path and insert it into a form. The relevant part of the code follows: Function GetOpenFile(Optional varDirectory As Variant,...
17
by: Joe Laughlin | last post by:
I've not used C much before, so I don't know how robust or good this code is. I'd appreciate any feedback or criticisms anyone has! Thanks, Joe #include <stdio.h> #include <string.h>
18
by: walterbyrd | last post by:
I am trying to develop an app where: the same file, in the same place, will be uploaded, and then processed. Everything I can find about uploading a file, uses a form that requires the user to...
1
by: Adi | last post by:
Hi, I am having a problem in exporting the file into csv format from a website. First the name I put in the export 'box' comes over with "%" "" and other odd characters in the FILE name and the...
4
by: carmelo | last post by:
Hi! I need to read and store data from a file, but I don't the name of it; Is this code correct and is there a better way to do this thing?? int main() { cout << " type file name:" char *...
185
by: jacob navia | last post by:
Hi We are rewriting the libc for the 64 bit version of lcc-win and we have added a new field in the FILE structure: char *FileName; fopen() will save the file name and an accessor function will...
9
by: Bill David | last post by:
I know it's very strange to do that since we have the file name when we call: int open(const char *pathname, int oflag,...); And we can store the file name for later usage. But I just wonder if...
4
by: liberty1 | last post by:
Hi everyone. I appreciate your effort at helping newbies like me. I have the following problems and will appreciate urgent help. PROBLEM NUMBER 1: Using PHP and MySQL, I am able to upload...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.