collapse collapse

* Who's Online

  • Dot Guests: 70
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

* Board Stats

  • stats Total Members: 88
  • stats Total Posts: 11164
  • stats Total Topics: 1700
  • stats Total Categories: 4
  • stats Total Boards: 76
  • stats Most Online: 1470

Author Topic: [38] Searching for Files  (Read 2283 times)

0 Members and 1 Guest are viewing this topic.

Offline Celestialkey

  • Administrator
  • Hero Member
  • *
  • Posts: 3962
  • Reputation 4874
  • Gender: Male
  • Its Alive!!
    • View Profile
    • www.CelestialCoding.com
[38] Searching for Files
« on: January 22, 2009, 08:42:44 pm »
Code: [Select]
#include <io.h> // WE need the struct _finddata_t in this header file
#include <direct.h> // We need the function _chdir() in here
#include <fstream> // Needed for opening files
#include <iostream> // Basic stuff
#include <string> // Also basic

using namespace std;



int main()
{
string sFile;
string sPath;

cout << "Enter the Location of the file.\n> ";
cin >> sPath;

if(_chdir(sPath.c_str()) == -1) // Simple error checking, it attempts to change the directory, -1 means it failed
{
cout << "Location does no exist! You fucked up sir!\n";
return -1;
}

cout << "Enter the File Name now please.\n> ";
cin >> sFile;

if(sPath[sPath.length()-1] != '\\') // Check to make sure there is a single slash at the end
sPath[sPath.length()] = '\\'; // We add a slash, in programmed two slashs = 1 slash

_finddata_t Search = {0}; // We make a struct copy of _finddata_t and name it Search thne set all values to 0
sPath.append(sFile); // Add the file name to the end of the directory

if(_findfirst(sPath.c_str(), &Search)) // Search for the file with _findfirst and put the information in &Search
{
cout << "Found file!\n";
_fcloseall(); // Close all streams opened up (_findfirst)
}
else
{
cout << "I had problems finding the file requested.\n";
}

getchar();
// system("pause"); // Uncomment this line if the program flashes on screeen or appears to not work correctly

return 0;
}
Created By: Eczuo
Quote
I have noticed that people who claim that everything is predestined, and we can do nothing to change it, look both ways before they cross the road.
Quote
I'd prefer to die standing, than to live on my knees - Che Guevara
Quote
If you change the way you look at something, does that something change in any way?
- Quantum Theory

Hacking
Quote
Never in the field of human conflict was so much owed by so many to so few. - Winston Churchill


Quote from: Revelations 12:4
And his tail drew the third part of the stars of heaven, and did cast them into the earth; and the dragon stood before the woman which was ready to be delivered, for to devour her child as soon as it was born.

Quote
It takes skill to build an empire. It takes an idiot to maintain it.

Offline NightSky

  • Regular Members
  • Hero Member
  • *
  • Posts: 711
  • Reputation 803
  • Gender: Male
  • Too Good.
    • View Profile
Re: [38] Searching for Files
« Reply #1 on: June 19, 2009, 02:35:07 pm »
Okay. . after retyping it 4 times. . (1once i tried copy / paste)
IT FINALLY WORKED D=<

. . . . turns out i left out a "\" and a space T_T







-Geee, waht a greaet way to start C++ ._.
« Last Edit: June 19, 2009, 02:38:31 pm by NightSky »

Offline Celestialkey

  • Administrator
  • Hero Member
  • *
  • Posts: 3962
  • Reputation 4874
  • Gender: Male
  • Its Alive!!
    • View Profile
    • www.CelestialCoding.com
Re: [38] Searching for Files
« Reply #2 on: June 19, 2009, 03:00:18 pm »
Curious to why your "starting" C++ with a fairly advanced topic...
Created By: Eczuo
Quote
I have noticed that people who claim that everything is predestined, and we can do nothing to change it, look both ways before they cross the road.
Quote
I'd prefer to die standing, than to live on my knees - Che Guevara
Quote
If you change the way you look at something, does that something change in any way?
- Quantum Theory

Hacking
Quote
Never in the field of human conflict was so much owed by so many to so few. - Winston Churchill


Quote from: Revelations 12:4
And his tail drew the third part of the stars of heaven, and did cast them into the earth; and the dragon stood before the woman which was ready to be delivered, for to devour her child as soon as it was born.

Quote
It takes skill to build an empire. It takes an idiot to maintain it.

Offline NightSky

  • Regular Members
  • Hero Member
  • *
  • Posts: 711
  • Reputation 803
  • Gender: Male
  • Too Good.
    • View Profile
Re: [38] Searching for Files
« Reply #3 on: June 19, 2009, 03:31:47 pm »
i can cope.

 

Donate


* Search


* Recent Posts

I miss the chatbox by Shishka
[August 27, 2019, 11:52:39 pm]


Image Comparison by Shishka
[May 15, 2017, 01:18:02 pm]


Re: srchub - free source code hosting by Nathan
[December 14, 2015, 11:37:02 pm]


Re: srchub - free source code hosting by Celestialkey
[November 27, 2015, 08:51:42 am]


Updates by Nathan
[October 30, 2015, 08:27:36 pm]