C++ :: Listing Files From A Given Directory

Aug 5, 2013

I tried listing files using the code given in "[URL] ..." the program listed all the files present in the current dirctory but if i change the drive and the directory to such as

"C:UsersBaaooDownloadsdirect.h function"

the program does not list files name.

#include <iostream>
#include <dirent.h>
using namespace std;
int main() {

DIR* dir;
dirent* pdir;

[Code] .....

View 1 Replies


ADVERTISEMENT

C++ :: Listing Files With Boost Filesystem

Jun 7, 2013

I have the following code which is based of the tut3.cpp example at: [URL] ....

However, I'm not entirely sure how to retrieve the full file path which I'd like to use to get the file size. So essentially the aim is to go through a directory and list all the file sizes.

Code:
if (exists(p)) {
if (is_directory(p)) {
cout << p << " is a directory containing:
";
copy(directory_iterator(p), directory_iterator(), // directory_iterator::value_type

[Code] ....

View 1 Replies View Related

C++ :: Show Pictures Randomly Without Listing Names Of Files

Apr 22, 2014

i was making a quiz and i want to show some pictures as questions to recognize i but i don't know how to show different pictures without listing the names of the files in the program, i mean i will generate a random no and based on the no the file name should change in the code like if the no is 1 it should find '1.jpg' and show it and if the no next time comes 23 then it should find '23.jpg'.

View 9 Replies View Related

C :: Merging All TXT Files In A Directory

Dec 6, 2013

I'm writing a program to merge all .txt files in a directory. I had the code working and then made small change. It started crashing and I couldn't get it back to working.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <unistd.h>
#include <string.h>
#include <sys/stat.h>

[Code] ....

It's crashing around the

Code: while(!feof(in)){ .

If I comment that section out, the code still works. But, I know that portion of the code works to copy text from one file to another! It's actually from the Schildt complete C reference and I have tested it several times on it's own.

View 5 Replies View Related

C++ :: Capturing Files In A Directory

Jan 9, 2013

I'm using the following code to capture all files in a directory - but when I pass the "path" var such as "C:SomeDir" ffd.cFileName is just simply "SomeDir" and is seen as a valid folder and no more files are processed.. I'm trying to get the contents in that folder. I'm following this example here - [URL] .....

Code:
bool ListFiles(TCHAR* path) {
HANDLE hFind = INVALID_HANDLE_VALUE;
WIN32_FIND_DATA ffd;
TCHAR * spec = new TCHAR[_MAX_PATH];
static std::stack<TCHAR*> directories;

[Code] .....

View 14 Replies View Related

C :: Error While Reading Files In Directory

Sep 7, 2014

I use this header dirent.h to get list of files in directory

[URL] .....

I am using code::blocks on windows XP.

Directory "kernels_source" is placed in project's directory where I am running the code.

Code:

#include "include/types.h"
#include "include/gaussian.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

[Code]....

View 10 Replies View Related

C++ :: Output Only Few Files Using Regex From Current Directory

Nov 20, 2013

I'm trying to output only a few files, using regex, from the current directory, this is my main code:

Code:
// main.cpp
{
char * _dir = new char[MAX_PATH];
getcwd(_dir, MAX_PATH);
unique_ptr<CExtractor> _ptr(new CExtractor(_dir));
delete[] _dir;
}

Code:
// CExtractor.cpp
DIR *pdir = NULL;
struct dirent *pent = NULL;
pdir = opendir(_cwd.c_str());
while ((pent = readdir(pdir)) && (pent->d_type != DT_DIR)) {
if (regex_match(pent->d_name, regex(".(in|txt)$"), std::regex_constants::icase)) {
cout << pent->d_name << endl;
}
}
closedir(pdir);

My code is compiled correctly, but when I run my binary, nothings is outputed..here are my files in the current directpory:

aclocal.m4 config.guess config.status depcomp m4 NEWS
AUTHORS config.h config.sub INSTALL Makefile README
autom4te.cache config.h.in configure install-sh Makefile.am src
ChangeLog config.h.in~ configure.ac libtool Makefile.in stamp-h1
compile config.log COPYING ltmain.sh missing

I have a few "in" files

View 1 Replies View Related

C++ :: Implement Hashing Of Text Files In Directory

Feb 9, 2014

Writ a program to implement hashing of text files in a directory to find files with the same content?

View 1 Replies View Related

C/C++ :: Read Through Files Of Directory Name Passed As Argument

May 3, 2014

write a code using vs studio 8 to read a diretory name as argument and then open the directory and read each file one at a time and find the match for a string passed as an nother argument in the lines of each file. When it matches create a file and write in that output file the file name whetre the match found, the line number and line which matched.

My vis does not have dirent.h. so please use another ways to read directory call witha system acll and then then extract the fienames in a file(use some primitive way to open the the directory)

I cant do this parts

(1) read a directory

(2) create a file with only file names

(3) read file names ans open the files one at a time till the end of the file reached

View 3 Replies View Related

C++ :: Processing Multiple Files From Single Directory?

Feb 21, 2012

I've tried to form together the following code so that I can process multiple files from one user specified directory. However, when I run the program it works great for the first file, but all other files are blank. The problem starts on the following line:

while(FileIn.good())

//---------------------------------------------------
#include <fstream>
#include <iostream>
#include <dirent.h>
#include <sys/stat.h>
using namespace std;
struct dirent *dirp;

[code]....

View 14 Replies View Related

C/C++ :: Include (Text) Files From Directory (1 By 1) Automatically And Print It

Jun 10, 2014

#include<iostream>
#include<conio.h>
#include<fstream>
#include<windows.h>
using namespace std;
int main(){
string ptr,a;
string b="E:project";

[Code] ....

View 4 Replies View Related

C :: Program That Acts As File Manager For All Files And Folders In Directory

Jul 29, 2013

I need to write a program that acts as a file manager for all the files and folders in the directory given as an argv parameter and all of its subdirectories. This means be able to move, rename, delete the files in the sub directories. Also I need to be able to store the structure of folders and files in a binary tree adt (I have one already). But I'm not sure what libraries to use with this and how do I open a directory is it like a file with fopen?

View 4 Replies View Related

C++ :: How To Implement Array Based Listing And Searching

Nov 23, 2014

I'm trying to open a text file from my computer and randomly output a random line of text (string) onto the console. How do I go about doing this?

So for example, if my text file, "StringTextFile.txt" had 50 rows of strings datas (not integers or chars), how would I randomly generate a line of word from the 50 rows of words in the StringTextFile.txt and output it onto the console?

This is how far I've gotten, which isn't much, but somewhere. I don't even know if my code even makes sense, at this point I'm just randomly shoving code together.

#include <fstream>
#include <iostream>
#include <string>
#include <iomanip>
#include <string>
#include <cstdlib>
#include <ctime>

[code]......

View 1 Replies View Related

C :: Print Listing With Line Numbers - Cannot Execute / Run Program

Feb 18, 2013

The problem is with the first "Type and Run," where the code looks like this:

Code:
/* print_it.c--This program prints a listing with line numbers! */
#include <stdlib.h>
#include <stdio.h>

void do_heading(char *filename);
int line = 0, page = 0;

[Code] ....

I am using the gcc compiler in Ubuntu 12.04 LTS and I get the following error:

Code:
print_it.c: In function "main":
print_it.c:36:15: error: "stdprn" undeclared (first use in this function)
print_it.c:36:15: note: each undeclared identifier is reported only once for each function it appears in
print_it.c: In function "do_heading":
print_it.c:49:16: error: "stdprn" undeclared (first use in this function)

I was told that "stdprn" can be recognised by a DOS based compiler and the book says I can try using "stdout" instead. It looks like this now:

Code:
/* print_it.c--This program prints a listing with line numbers! */
#include <stdlib.h>
#include <stdio.h>

void do_heading(char *filename);
int line = 0, page = 0;

[Code] .....

It compiled OK with the gcc compiler but I only get this when I run the program:

Code:
Proper Usage is:
print_it filename.ext

I am not sure whether I should continue looking into this but even when I tried compiling and running it on Windows, the .exe file won't even launch. The other ones do but this first one doesn't.

Questions:

1. What should be done to make this program run?
2. Even though the book says "don't care" if the reader does not understand the items (It's Day 1/Lesson 1), I would still like it to run as I don't want to experience compiling and running problems in the future. Should I even bother doing this section of the book or is it obsolete and should be skipped?

View 6 Replies View Related

C :: Program To Hide Files Behind Other Files Using Alternate Data Streams

Apr 5, 2013

I am writing a program to hide files behind other files using Alternate Data Streams in Windows NTFS file systems.

The program is as follows:

Code:

#include <stdio.h>
#include <stdlib.h>
int main(void){
char hostfile[75], hiddenfile[75], hiddenFileName[15] ;
printf("Enter the name(with extension) and path of the file whose behind you want to hide another file: ");
scanf("%75s", hostfile);

[Code]...

The complier is showing error as "Extra Perimeter in call to system" but I am not getting where?

View 4 Replies View Related

C++ :: Display Last 1000 Lines From Multiple Text Files (log Files)

Jan 16, 2014

I am writing a piece of code that requires me to display the last 1000 lines from a multiple text files (log files). FYI, I am running on Linux and using g++.

I have a log file from which - if it contains more than 1000 lines, I need to display the last 1000 lines. However, the log file could get rotated. So, in case where the current log file contains less than 1000 lines, I have to go to older log file and display the remaining. For e.g., if log got rotated and new log file contains 20 lines, I have to display the 980 lines from old log file + 20 from current log files.

What is the best way to do this? Even an outline algorithm will work.

View 6 Replies View Related

C++ ::  Creating A New Directory?

May 11, 2013

How do you create a new directory in C++? I would like to do this using the standard library and no external, third party or non standard libraries/headers. I need to do this without calling system() or system("mkdir").

View 7 Replies View Related

C++ :: How To Change Directory

Apr 24, 2014

How to change directory in c++ ( windows ) I want to go to the folder "example2" and I delete some files and then return to the original folder c++ - windows

View 7 Replies View Related

C++ :: How To Protect Entire TMP Directory

Mar 13, 2014

The general design of my app work-flow:

My application is processing a large amount of data (approx. 50 - 100 GB of txt data). given the machine regular user usually has, my app is writing some tmp data into a local tmp directory. and this is working just fine until users get comfortable with my software and start changing that content of local tmp dir (while the program is running). which does not give any problems like crashing a program if handled at the right time but produces wrong results in the end. now this is not my problem but i would still like to somehow restrict users from even peeking into the tmp dir. I am just tired of getting emails saying my software is cr.... (maybe it is but i don't think it is because of that)

So is it possible to somehow encrypt the entire dir so that only the program has access to it . it would be even better if the dir could look as some encrypted index file so that when user sees the warning :

"tmp" may be a binary file. See it anyway?

View 6 Replies View Related

C :: How To Get User Home Directory

Oct 20, 2014

I want to obtain the user's home directory. I know it can be done with getenv("HOME"), but if I'll inspect the value of the enviroment variable HOME, it might work when I run it now, but it won't work on Windows, since windows uses HOMEPATH to save the user's home directory.

Is there a different, more cross-platform way to do it?

View 5 Replies View Related

C :: Using Process ID As The Name Of File Directory

Jan 31, 2015

I need my Unix program to generate a directory with a format like this: "hinesro.<pid>". I have some code that mostly works, except for the directory ends up with a question mark on the end, like this: "hinesro.12345?". I need it to just display the directory without this question mark. Here is my code:

Code:

// Using headers sys/types.h, sys/stat.h, unistd.h, and stdio.h
int pid = getpid();
char prefix[] = "hinesro.";
char fileName[0];
sprintf(fileName, "%s%d
", prefix, pid);

[Code]...

View 13 Replies View Related

C++ :: Opening A File Within A Directory

Apr 26, 2013

I have problems opening a file within a directory.

#include <dirent.h>
#include <string>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

[Code] .....

Error Message:
$ ./dirsearch ~/Documents/College/textfiles/
[..]
[yomama.txt]
Error : Failed to open entry file - No such file or directory

Here are my current file permissions:
textfiles$ ls -l
total 8
-rw-rw-rw- 1 jav jav 7 Apr 26 13:14 moretext.txt
-rw-rw-rw- 1 jav jav 10 Apr 26 12:38 yomama.txt

View 6 Replies View Related

C++ :: DLL Search Directory Order

Aug 29, 2013

I was working on a program. "hey if this program were to be published it would be bad for people to see all dll files are in the exe directory"....

So I wondered if there is a way to make compiler see a folder in the same directory with exe file which holds all dll files?

Also look at some programs and saw they have a dll folder which holds dll files....

View 1 Replies View Related

C++ :: Can't Open A Directory In Terminal

Jan 12, 2015

Taking a OS course and my professor gave us files to reference in a directory located at ~agw/class/os/share/proj3. But when I typed this into the terminal I keep getting a permission denied error message.

[lastname@erdos ~]$ ls
dead.letter Desktop Documents Downloads Music Pictures private Public public_html Templates Videos
[lastname@erdos ~]$ ~agw/class/os/share/proj3
/u/sobolev/agw/class/os/share/proj3: Permission denied.
[lastname@erdos ~]$

I'm not sure what I am doing wrong. Ive opened shared directories for this class before and had no issues.

View 1 Replies View Related

C++ :: Cannot Open A Directory In Terminal

Dec 9, 2013

Taking a OS course and my professor gave us files to reference in a directory located at ~agw/class/os/share/proj3. But when I typed this into the terminal I keep getting a permission denied error message.

[lastname@erdos ~]$ ls
dead.letter Desktop Documents Downloads Music Pictures private Public public_html Templates Videos
[lastname@erdos ~]$ ~agw/class/os/share/proj3
/u/sobolev/agw/class/os/share/proj3: Permission denied.
[lastname@erdos ~]$

I've opened shared directories for this class before and had no issues.

View 2 Replies View Related

C/C++ :: Scan A Directory Recursively

Dec 19, 2014

I'm writing a C++ module that is meant to recursively scan a directory and I'm curious what yall think of my strategy.

The program is a music player and so I'm trying to make the directory scanner as lightweight and efficient as I can. I've decided I want to scan the files in two passes- first I just want to get a list of all music files that are found in a directory/subdirectories and then I want to process the list and search for id3s/other tags.

As I'm a scanning the directory, I've decided to store the temporary list in a linked list where each node is containing an array of 100 strings. I did this because I obviously don't know how long the list will be and I from my understanding of the C++ vector class it basically just makes over sized arrays and moves them when it runs out of space. That sounded rather clunky to me, as did a traditional linked list.. I didn't see the point of allocating memory that many times in a row.

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved