Zip folder in C#

This answer changes with .NET 4.5. Creating a zip file becomes incredibly easy. No third-party libraries will be required. string startPath = @”c:\example\start”; string zipPath = @”c:\example\result.zip”; string extractPath = @”c:\example\extract”; ZipFile.CreateFromDirectory(startPath, zipPath); ZipFile.ExtractToDirectory(zipPath, extractPath);

How do I create crossplatform file paths in Go?

For creating and manipulating OS-specific paths directly use os.PathSeparator and the path/filepath package. An alternative method is to always use “https://stackoverflow.com/” and the path package throughout your program. The path package uses “https://stackoverflow.com/” as path separator irrespective of the OS. Before opening or creating a file, convert the /-separated path into an OS-specific path string … Read more

Get parent directory of running script

If your script is located in /var/www/dir/index.php then the following would return: dirname(__FILE__); // /var/www/dir or dirname( dirname(__FILE__) ); // /var/www Edit This is a technique used in many frameworks to determine relative paths from the app_root. File structure: /var/ www/ index.php subdir/ library.php index.php is my dispatcher/boostrap file that all requests are routed to: … Read more

How to remove a directory in R?

See help ?unlink: Value 0 for success, 1 for failure, invisibly. Not deleting a non-existent file is not a failure, nor is being unable to delete a directory if recursive = FALSE. However, missing values in x are regarded as failures. In the case where there is a folder foo the unlink call without recursive=TRUE … Read more

Portable way to check if directory exists [Windows/Linux, C]

stat() works on Linux., UNIX and Windows as well: #include <sys/types.h> #include <sys/stat.h> struct stat info; if( stat( pathname, &info ) != 0 ) printf( “cannot access %s\n”, pathname ); else if( info.st_mode & S_IFDIR ) // S_ISDIR() doesn’t exist on my windows printf( “%s is a directory\n”, pathname ); else printf( “%s is no … Read more

Finding the root directory of a multi module Maven reactor project

use ${session.executionRootDirectory} For the record, ${session.executionRootDirectory} works for me in pom files in Maven 3.0.3. That property will be the directory you’re running in, so run the parent project and each module can get the path to that root directory. I put the plugin configuration that uses this property in the parent pom so that … Read more

Create a directory if it doesn’t exist

Use the WINAPI CreateDirectory() function to create a folder. You can use this function without checking if the directory already exists as it will fail but GetLastError() will return ERROR_ALREADY_EXISTS: if (CreateDirectory(OutputFolder.c_str(), NULL) || ERROR_ALREADY_EXISTS == GetLastError()) { // CopyFile(…) } else { // Failed to create directory. } The code for constructing the target … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)