Delete directories recursively in Java
You should check out Apache’s commons-io. It has a FileUtils class that will do what you want. FileUtils.deleteDirectory(new File(“directory”));
You should check out Apache’s commons-io. It has a FileUtils class that will do what you want. FileUtils.deleteDirectory(new File(“directory”));
Here’s some advice from someone with an environment where we have folders containing tens of millions of files. A folder stores the index information (links to child files & child folder) in an index file. This file will get very large when you have a lot of children. Note that it doesn’t distinguish between a … Read more
Optimum buffer size is related to a number of things: file system block size, CPU cache size and cache latency. Most file systems are configured to use block sizes of 4096 or 8192. In theory, if you configure your buffer size so you are reading a few bytes more than the disk block, the operations … Read more
Just urlencode the string desired as a filename. All characters returned from urlencode are valid in filenames (NTFS/HFS/UNIX), then you can just urldecode the filenames back to UTF-8 (or whatever encoding they were in). Caveats (all apply to the solutions below as well): After url-encoding, the filename must be less that 255 characters (probably bytes). … Read more
From MSDN’s “Naming a File or Directory,” here are the general conventions for what a legal file name is under Windows: You may use any character in the current code page (Unicode/ANSI above 127), except: < > : ” / \ | ? * Characters whose integer representations are 0-31 (less than ASCII space) Any … Read more
Full control over file attributes is available in Java 7, as part of the “new” New IO facility (NIO.2). For example, POSIX permissions can be set on an existing file with setPosixFilePermissions(), or atomically at file creation with methods like createFile() or newByteChannel(). You can create a set of permissions using EnumSet.of(), but the helper … Read more
For .NET 4.0 and later, var files = Directory.EnumerateFiles(“C:\\path”, “*.*”, SearchOption.AllDirectories) .Where(s => s.EndsWith(“.mp3”) || s.EndsWith(“.jpg”)); For earlier versions of .NET, var files = Directory.GetFiles(“C:\\path”, “*.*”, SearchOption.AllDirectories) .Where(s => s.EndsWith(“.mp3”) || s.EndsWith(“.jpg”)); edit: Please read the comments. The improvement that Paul Farry suggests, and the memory/performance issue that Christian.K points out are both very important.
FAT32: Maximum number of files: 268,173,300 Maximum number of files per directory: 216 – 1 (65,535) Maximum file size: 2 GiB – 1 without LFS, 4 GiB – 1 with NTFS: Maximum number of files: 232 – 1 (4,294,967,295) Maximum file size Implementation: 244 – 26 bytes (16 TiB – 64 KiB) Theoretical: 264 – 26 bytes (16 EiB – 64 KiB) Maximum volume size Implementation: 232 – 1 clusters (256 TiB – 64 KiB) Theoretical: 264 – 1 clusters (1 YiB – 64 KiB) ext2: Maximum number of files: 1018 … Read more
Look up the access() function, found in unistd.h. You can replace your function with if( access( fname, F_OK ) == 0 ) { // file exists } else { // file doesn’t exist } Under Windows (VC) unistd.h does not exist. To make it work it is necessary to define: #ifdef WIN32 #include <io.h> #define … Read more
Modify the open_basedir settings in your hosting account and set them to none. Find the open_basedir setting given under ‘PHP Settings’ area of your Plesk/cPanel. Set it to ‘none’ from the dropdown given there. I have shown them in the Plesk panel picture.