I am having trouble in storing the files in a string array from a directory in c++, using System::IO::Directory::GetFiles in c++
Also would like to know if we could copy an entire folder to a new destination/ in c++ like given in http://www.codeproject.com/KB/files/xdirectorycopy.aspx for c#
You can store the file names from a directory in a managed array like this:
System::String ^path = "c:\\";
cli::array<System::String ^>^ a = System::IO::Directory::GetFiles(path);
Console::WriteLine(a[0]);
Console::ReadKey();
As for how would you copy an entire folder... Simply recurse from a given root directory creating each directory and copying the files to the new location. If you are asking for code for this, then please say so, but at least try to figure it out for yourself first (i.e. show me what you have so far).
Check out the file listing program in Boost::FileSystem: http://www.boost.org/doc/libs/1_41_0/libs/filesystem/example/simple_ls.cpp. They iterate over all files, printing the paths, but it's trivial to store them instead.
Assuming you're on Win32, you're looking for the FindFirstFile and FindNextFile APIs.
C/C++ does not define a standard way to do this, though Boost::Filesystem provides a method if you need cross platform support.
Related
I'm using grunt-init to build a template for a site structure I repeat regularly.
The template.js file uses the init.copyAndProcess function to customize most of files but a few of them get corrupted by the file processing (some fonts and image files) and I want to include those files in the 'noProcess' option. If these files all existed in the same directory, I could use the noProcess option as mentioned in the documentation [ See: http://gruntjs.com/project-scaffolding#copying-files ] and pass in a string like and it works:
var files = init.filesToCopy(props);
init.copyAndProcess(files, props, {noProcess: 'app/fonts/**'} );
Unfortunately the files that I need to have no processing performed on are not all in the same directory and I'd like to be able to pass in an array of them, something like the following block of code, but this does not work.
var files = init.filesToCopy(props);
init.copyAndProcess(files, props, {noProcess: ['app/fonts/**', 'app/images/*.png', 'app/images/*.jpg']} );
Any thoughts on how I can have multiple targets for the 'noProcess' option?
As soon as I posted the question, I realized that my proposed code did work. I simply had an invalid path when I'd renamed my 'app' directory to 'dev'.
I have a wxFilenName mydir that should point to a writeable directory. Ultimately, mydir has been obtained via mydir=otherfilename.GetPath() (though via some disgressions maybe). Assuming that mydirrefers to (on a Windows box) C:\foo\bar, I need to ensure that C:\foo\barexists and is a directory (not a file) and I have write permissions (so I might create C:\foo\bar\baz).
What I do is to check mydir.IsOk() && mydir.DirExists() && mydir.IsDirWriteable(), but I suspect this does not do what I want. From reading the wxwidgets docs, I gather that it does distinguish between a wxFileName referencing C:\foo\barin the sense of "the file/dir bar in the directory C:\foo" versus C:\foo\bar in the sense of "the directoy C:\foo\bar and no particular file in it") so that I'd expect my method to work as GetPath()should return such a "pure" directory. However, I suspect (and testing indicates) that my checks really check if C:\foo is a writeable directory ...
What would be a better method (within the wxWidgets framework)? Do I really need to append some dummy filename before performing my checks?
Use wxFileName::DirName() to create an object representing a directory.
I am using Flex, Flash Builder 4.5 and Extension Builder 2.0.0 and I use the "nochump ziplib" library to generate a ZIP file. I want to create a new folder in created ZIP file, but I can't find such function function in the "nochump" library.
Can anyone please tell me if there is any function to add new folder in a ZIP file or a library which can help me do this?
The directories are not first-class citizens in the ZIP format.
The archive is built from "entries" - plain files with their relative locations to the "central directory" (the "root" of the archive). This means that the ZIP file is composed from entries like "pictures/1.jpg", "doc/old/1.txt" etc. You don't have separate entries for the "pictures", "doc" or "doc/old" directories.
You can't create a new directory directly. Instead of creating a new directory first (such as "newDir") you may want to create a file (entry) inside instead (such as "newDir/1.txt") and "newDir" will appear as directory when you open the resulting ZIP file.
If you insist on having an empty directory in the archive, you may try the hacky way - adding entries like "newDir/." with zero length. But this may not work with your library.
The Wikipedia article for the ZIP format has all the theory explained pretty well.
If I use the write method, where will these files be written? Example:
write(results, file="myFile.csv", ncolumns=1)
I don't specify a full path so I assume it's writing to some default directory. I checked program files, but it's not there. Suggestions on where to look?
If you type from within your R session:
getwd()
You should be able to retrieve your current working directory, that's the place where the files should be saved to.
You can also choose to set your workspace to a location of your desire:
setwd('C:/Users/.../Documents/R/Scripts')
Files you save will automatically be written to this new location.
I've just started learning discovering the changes to Drupal 7, and I just found the files[] array now required in the mymodule.info. From what I've found, it is required to add the mymodule.module file to the list, but what other uses does it have?
From what I've read I figured I should be able to separate my code into several files, for example I wanted to make a mymodule.blocks.inc to contain all the code for my blocks, but it seems like the mymodule_block_info() function never runs.
Am I doing something wrong, or is this not how it is supposed to be used?
As the documentation says:
files (Optional) Drupal now supports a dynamic-loading code registry.
To support it, all modules must now declare any code files containing class or interface declarations in the .info file.
This is only used if the file you specify in files[] contains a class or an interface. If so, the file will be auto-loaded only when needed.
No other files should be declared using files[].
At the beginning it was to make a files registry for each module, but it's not longer used as Drupal do it by himself.
If you want separate your module in multiple files, you should include them in the top of your .module file.
The way I see it, files specified as files[] are meant to be supporting files and called upon when needed. Implemented default Drupal hooks should be specified in the .module file or in the $module.$group.inc file in order for Drupal to recognize them. See hook_hook_info().
Also, see the note in the documentation under files at http://drupal.org/node/542202.