How can I rename files of which I don't know the extension? - c++

I have a directory with these files:
one.txt
two.mp3
three.bmp
Is there any way to rename files using MoveFile() but without specifying the extension of the file (all the files have different filenames)?
If not, how can I rename these files to anything I want, when I only know the
one
two
three
?

You'll have to use the underlying OS API to scan through the directory for files and compare each filename with your desired prefix. Here is another question that shows you how to list the contents of a directory in Windows.

Once you know prefix read the filelist of the directory and find a valid filename with that prefix, and use that filename with the function.

Related

How to check whether a folder exists or not in gcp cloud storage out of 1 million folders

For example I have structure like this.
bucketname/checked/folder1/some files
bucketname/checked/folder2/some files
bucketname/checked/folder3/some files
bucketname/checked/folder4/some files
bucketname/checked/folder5/some files
bucketname/checked/folder6/some files
bucketname/checked/folder7/some files
bucketname/checked/folder8/some files
bucketname/checked/folder9/some files
bucketname/checked/folder10/some files
bucketname/checked/folder11/some files
......
......
bucketname/checked/folder-1million/some files
Now,
1. If I have to check whether folder99999 exists or not. So,what would be the best way to check it (we have information of folder name - folder99999) ?
2. If we simply check path that exists or not, and if not then it means, folder don't exists. would it work fine If we have millions of folders?
3. Which data structure gcp uses to retrieve the folder data ?
The true answer is this one provided by John: folder doesn't exist. All the files are stored at the root directory (bucket level) and the file name is the full path. By human convention, the / is the folder separator and the console display fake folders.
If you haven't files in a "folder", the "folder" doesn't exist, it's not interpreted/deduced from the name fully qualified path. The folder is not a Cloud Storage resource
It's also for that reason that you search only by path prefix
However, it depends what you want to check. If you exactly know which folder you want to check and validate, and if there is at least one file in it, you can directly list the files with the folder path as prefix.

Reading a folder

I'm using the following code from this website about how to read from a folder to get all the files. I'm then "pushing" them into a string vector.
My question is, when I read all the files, I get "." and ".." as my first to "files" read from the folder; what are these two "files"?
Furthermore, this code does achieve the goal. I'm just curious as to what these two "files" really are.
I'm using Xcode, and this is in C++.
Let me know if you need more info.
In linux and unix there is no difference between a file and a directory. Note that in the case of these dot files they are actually not "real files" though, that's another topic.
The "." is a special file in the folder which means "the current directory" and ".." is another special file which means "the parent directory".
Directories do not contain files. Directories contain names. The names are links to objects in the filesystem. The names . and .. are links to the directory and its parent, respectively.

Why doesn't Xcode6 see included header files

I'm trying to build opencv2 as a universal framework. I am systematically removing the files/folders that I do not need. But I am running into this issue where the include files are not found. See the image below:
The following image clearly shows that the file is indeed there.
One of the contractors working with us said he had put the include files into the same directory as the source files and rename them according to their file structure but using "." instead of "/" as shown below:
But that means that I must go through all of the files that include files and change the include statement to use "." instead of "/". REALLY?
Is this true? Or do we have a configuration set wrong?
You need to setup search paths for your target in Build Settings->Search Paths->Header search paths.

Get list of files in application directory

I am developing a C++ application for win32 console
I need to get list of files in my application directory
(for example if my application had been started in C:\arash\app\ I need list of files in this folder)
I searched and find FindFirstFile function in windows.h header , But this function need a directory path .
Can I use this function for getting list of files in my application running directory?
Thanks
Use GetModuleFileName() with a NULL module handle to get the path and filename of the .exe file. You can then strip off the filename portion, and use the remaining path as needed.
The current working directory is '.'.
As noted in comments, this isn't necessarily the directory you want.

having file names and delete them

I want to have access to all files of a folder and have a list of them and work with them.
For example: there is a folder named "new folder" and consist of files : 1.txt and 2.txt
I don't know what are in the folder new folder. So I want a list of files in it .
Hence the questions are :
1- How can I have such this list?
2- How can I delete a file (e.g 2.txt) whether i know there is file with this name or not.
3- Is it possible to figure out has a txt file been used or not (whether it is empty or not)
thanks;
I'd use Boost filesystem to analyze folder content, and remove to delete the file. You will find in filesystem tutorial some sample that will ease your work.
edit: remove(path) it's available in boost filesystem.