delete-directory

Bash scripting: Deleting the oldest directory

本小妞迷上赌 提交于 2019-11-29 10:49:37
I want to look for the oldest directory (inside a directory), and delete it. I am using the following: rm -R $(ls -1t | tail -1) ls -1t | tail -1 does indeed gives me the oldest directory, the the problem is that it is not deleting the directory, and that it also list files. How could I please fix that? This is not pretty but it works: rm -R $(ls -lt | grep '^d' | tail -1 | tr " " "\n" | tail -1) rm -R "$(find . -maxdepth 1 -type d -printf '%T@\t%p\n' | sort -r | tail -n 1 | sed 's/[0-9]*\.[0-9]*\t//')" This works also with directory whose name contains spaces, tabs or starts with a "-". rm -R

How to recursively delete an entire directory with PowerShell 2.0?

一曲冷凌霜 提交于 2019-11-28 13:25:01
问题 What is the simplest way to forcefully delete a directory and all its subdirectories in PowerShell? I am using PowerShell V2 in Windows 7. I have learned from several sources that the most obvious command, Remove-Item $targetDir -Recurse -Force , does not work correctly. This includes a statement in the PowerShell V2 online help (found using Get-Help Remove-Item -Examples ) that states: ...Because the Recurse parameter in this cmdlet is faulty, the command uses the Get-Childitem cmdlet to get

Batch file and DEL errorlevel 0 issue

陌路散爱 提交于 2019-11-28 12:54:56
The batch has to remove files and directories from specific locations and output success or stdout/stderr messages to a new .txt file. I have created the most of the script and it performs exactly as it should, except when the deletion is successful it moves forward to the next line rather than echo a 'successful' message on the log. echo Basic Deletion Batch Script > results.txt @echo off call :filelog >> results.txt 2>&1 notepad results.txt exit /b :filelog call :delete new.txt call :delete newer.txt call :delete newest.txt call :remove c:\NoSuchDirectory GOTO :EOF :delete echo deleting %1

Delete folder and all files/subdirectories

社会主义新天地 提交于 2019-11-28 09:40:23
How can I delete a folder with all it's files/subdirectories (recursive deletion) in C++? William Pursell Seriously: system( "rm -rf /path/to/directory" ) Perhaps more what you're looking for, but unix specific: /* Implement system( "rm -rf" ) */ #include <stdlib.h> #include <unistd.h> #include <stdio.h> #include <sys/syslimits.h> #include <ftw.h> /* Call unlink or rmdir on the path, as appropriate. */ int rm( const char *path, const struct stat *s, int flag, struct FTW *f ) { int status; int (*rm_func)( const char * ); switch( flag ) { default: rm_func = unlink; break; case FTW_DP: rm_func =

PHP: Simplest way to delete a folder (including its contents)

醉酒当歌 提交于 2019-11-28 06:16:20
The rmdir() function fails if the folder contains any files. I can loop through all of the the files in the directory with something like this: foreach (scandir($dir) as $item) { if ($item == '.' || $item == '..') continue; unlink($dir.DIRECTORY_SEPARATOR.$item); } rmdir($dir); Is there any way to just delete it all at once? Well, there's always system('/bin/rm -rf ' . escapeshellarg($dir)); where available. Yuriy rrmdir() -- recursively delete directories: function rrmdir($dir) { foreach(glob($dir . '/*') as $file) { if(is_dir($file)) rrmdir($file); else unlink($file); } rmdir($dir); }

How to delete empty subfolders with PowerShell?

对着背影说爱祢 提交于 2019-11-28 04:57:18
I have a share that is a "junk drawer" for end-users. They are able to create folders and subfolders as they see fit. I need to implement a script to delete files created more than 31 days old. I have that started with Powershell. I need to follow up the file deletion script by deleting subfolders that are now empty. Because of the nesting of subfolders, I need to avoid deleting a subfolder that is empty of files, but has a subfolder below it that contains a file. For example: FILE3a is 10 days old. FILE3 is 45 days old. I want to clean up the structure removing files older than 30 days, and

Deleting a directory results in application restart

眉间皱痕 提交于 2019-11-28 00:26:14
I have an application with 2 directories (books and export). If we create a book or a page of a book in the application a directory is added with the id of the page (this is for uploading resources). If we delete a page, the page (and it's directory) is removed from the database and the filesystem. However this resulted in a session loss (even an application restart). I've looked up some thing on google and found the following link . It seems to be a problem in ASP.NET 2.0 (and 3.5). Does anyone have a solution for this problem. We are now thinking about writing a service that will clean up

How to delete a folder in C++?

谁说我不能喝 提交于 2019-11-27 07:57:51
How can I delete a folder using C++? If no cross-platform way exists, then how to do it for the most-popular OSes - Windows, Linux, Mac, iOS, Android? Would a POSIX solution work for all of them? Edouard A. I strongly advise to use Boost.FileSystem. http://www.boost.org/doc/libs/1_38_0/libs/filesystem/doc/index.htm In your case that would be boost::filesystem::remove_all(yourPath) hB0 Delete folder (sub_folders and files) in Windows (VisualC++) not using Shell APIs, this is the best working sample: #include <string> #include <iostream> #include <windows.h> #include <conio.h> int

Batch file and DEL errorlevel 0 issue

时光毁灭记忆、已成空白 提交于 2019-11-27 07:16:58
问题 The batch has to remove files and directories from specific locations and output success or stdout/stderr messages to a new .txt file. I have created the most of the script and it performs exactly as it should, except when the deletion is successful it moves forward to the next line rather than echo a 'successful' message on the log. echo Basic Deletion Batch Script > results.txt @echo off call :filelog >> results.txt 2>&1 notepad results.txt exit /b :filelog call :delete new.txt call :delete

How to delete a folder with files using Java

一个人想着一个人 提交于 2019-11-27 03:21:36
I want to create and delete a directory using Java, but it isn't working. File index = new File("/home/Work/Indexer1"); if (!index.exists()) { index.mkdir(); } else { index.delete(); if (!index.exists()) { index.mkdir(); } } Java isn't able to delete folders with data in it. You have to delete all files before deleting the folder. Use something like: String[]entries = index.list(); for(String s: entries){ File currentFile = new File(index.getPath(),s); currentFile.delete(); } Then you should be able to delete the folder by using index.delete() Untested! Barry Knapp Just a one-liner. import org