473,320 Members | 2,080 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.

Detecting matching files?

Hello, I need help with writing a part of a program which I am working on, I was wondering how to check for a pre-existing file. The user's input in the program is what determines the name of the file written in the end, but I would like to know how to make the program check to see if a file matching that name already exists, and then alert the user. Also I was wondering how to delete a file if the name is a string and not a constant using, (I've just been using system("del filenamehere.file") but I can't make it work for a string).
May 24 '07 #1
5 1368
Silent1Mezzo
208 100+
What have you got so far?
May 24 '07 #2
ahammad
79
So the user types in the filename? Is the filename used so that it gets created and data gets printed to it?
May 24 '07 #3
The user types into a field their name, and from the first letter of their firstname and the last letter of their last name + their lastname it creates a textfile with this name. The part I need help with is how to detect if a file with a name matching the one the user is making exists already. So if a user named John mike Jacob entered this into the field and it created the file JmJacob, and then Jason mellon Jacob entered his name into the field, it wouldn't overwrite JmJacob with his information. I hope I explained what I'm asking a little more clearly.
May 24 '07 #4
weaknessforcats
9,208 Expert Mod 8TB
Just open the file. If the file is not there, it's safe to create it. Like this:

Expand|Select|Wrap|Line Numbers
  1. ifstream file;
  2. file.open("C:\\scratch\\aintnosuchfile.txt");
  3. if (file.fail())
  4. {
  5.     cout << "No such file ao I  will create it." << endl;
  6.      file.open("C:\\scratch\\aintnosuchfile.txt", ios::app);
  7. }
  8. else
  9. {
  10.   cout << "File exists already" << endl;
  11. }
  12.  
May 25 '07 #5
Thank you for the help
May 25 '07 #6

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

Similar topics

5
by: Jole | last post by:
Hi I'm writing a program that needs to read from a file. In order for the program to be robust, it should somehow check that the file isn't corrupt, or stuffed in any way. For example, that...
1
by: jeff | last post by:
Hiya I just woundering how would I go about detecting addition, deletion or change to files in a folder? Ideally id like to look at a linux directory and say watch all its contents and then...
9
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # Matching string patterns # # Sometimes you want to know if a string is of # particular pattern. Let's say in your website # you have converted all images...
3
by: Day Of The Eagle | last post by:
Jeff_Relf wrote: > ...yet you don't even know what RegEx is. > I'm looking at the source code for mono's Regex implementation right now. You can download that source here ( use the class...
2
by: Joecx | last post by:
Hi If I want to copy files using a pattern like: I want all files on a directory that start with 20050822 to be copied to a different directory. I can't get file.copy or copyfile to accept *.*...
3
by: Nathan Sokalski | last post by:
I have several pieces of data that I use the HttpApplicationState for, because they rarely change and are used by everyone. When these pieces of data are created, they are created either from...
8
by: EP | last post by:
Hi, I'm a bit green in this area and wonder to what extent there may be some existing Python tools (or if I have to scratch my head real hard for an appropriate algorithm... ) I'd hate to build...
6
by: andyalean1 | last post by:
Hello, I am trying to match an Id number that is shared across 2 xml files.I seem to be do the right thing bu it won`t display a match.Can you please help me find my error. I have a problem matching...
2
by: santhoshs | last post by:
Hello I am required to parse two files that contain email addresses and figure out a way to get the matching and non-matching email addresses from both the files. I was able to get the matching...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
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: 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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.