delete-file

Difference between unlink and rm on unix

烂漫一生 提交于 2019-12-04 15:14:48
Whats the real different between these two commands? Why is the system call to delete a file called unlink instead of delete ? Eliyahu Skoczylas You need to understand a bit about the original Unix file system to understand this very important question. Unlike other operating systems of its era (late 60s, early 70s) Unix did not store the file name together with the actual directory information (of where the file was stored on the disks.) Instead, Unix created a separate " Inode table " to contain the directory information, and identify the actual file, and then allowed separate text files to

Need a shell script that deletes all files except *.pdf

白昼怎懂夜的黑 提交于 2019-12-04 13:32:46
问题 Can anyone write a shell script that deletes all the files in the folder except those with pdf extension? 回答1: This will include all subdirectories: find . -type f ! -iname '*.pdf' -delete This will act only in the current directory: find . -maxdepth 1 -type f ! -iname '*.pdf' -delete 回答2: $ ls -1 | grep -v '.pdf$' | xargs -I {} rm -i {} Or, if you are confident: $ ls -1 | grep -v '.pdf$' | xargs -I {} rm {} Or, the bulletproof version: $ find . -maxdepth 1 -type f ! -iname '*.pdf' -delete

nAnt Deleting files older than 7 days old

拈花ヽ惹草 提交于 2019-12-04 12:14:24
问题 I would like to create a target that cleans log files older than 7 days old in a specific folder. I get an error when I try to put in a "date" element inside a fileset. How can I go about this? <delete> fileset basedir="${StageIISRoot}/MySite/App_Data/ErrorLog"> <date datetime="${datetime::now() - timespan::from-days(7)}" when="before"/> <include name="*.xml" /> </fileset> </delete> 回答1: I don't see any documentation for using the "date" element. You might consider something like this:

Unstage all deleted files in Git

跟風遠走 提交于 2019-12-04 11:54:09
问题 I want to unstage all file deletes. Is there an easy way? I want to apply this to the file pattern of all deletes. 回答1: The output of git status --porcelain is a great way to build one-liners and scripts for tasks like this: git status --porcelain | awk '$1 == "D" {print $2}' | xargs git reset HEAD 回答2: In case your path-/filenames returned from git status contain space characters, the call to awk can be modified to include the entire (quoted) path/filename including spaces: git status -

What's the “proper” way to delete files from a ClearCase snapshot?

南楼画角 提交于 2019-12-04 04:00:31
When I delete a file from my snapshot view, the next time I look at the snapshot in ClearCase Explorer, it shows the "??" checked-out-but-removed icon. When I run "Find Modified Files" on the snapshot, the deleted files aren't shown. Running "Update View" on the snapshot causes ClearCase to re-copy the missing files back into my view. What I want to happen is this: when I delete a file from my snapshot, and do an update, the file should be deleted from the view, just as if I had deleted it through ClearCase from a dynamic view. What's the best way to accomplish this? I would prefer to avoid a

What is the fastest way of deleting files in a directory? (Except specific file extension)

与世无争的帅哥 提交于 2019-12-04 03:12:53
I have seen questions like What is the best way to empty a directory? But I need to know, what is the fastest way of deleting all the files found within the directory, except any .zip files found. Smells like linq here... or what? By saying fastest way, I mean the Fastest execution time. If you are using .NET 4 you can benifit the smart way .NET now parallizing your functions. This code is the fasted way to do it. This scales with your numbers of cores on the processor too. DirectoryInfo di = new DirectoryInfo(yourDir); var files = di.GetFiles(); files.AsParallel().Where(f => f.Extension != "

Able to write/read file but unable to delete file SWIFT

限于喜欢 提交于 2019-12-04 01:40:58
问题 I store an .jpg image i the iOS documents directory. I can write files and read files but when it comes to deleting them it says that there is no such file but that cannot be because I can read it with the same url. Reading: let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true) let path = NSURL(fileURLWithPath: paths[0] as String) let fullPath = path.appendingPathComponent(info["pi"] as! String) let data = NSData(contentsOf: fullPath!) Deleting: let

How to debug “Sharing Violation” when trying to delete a file

牧云@^-^@ 提交于 2019-12-04 00:54:49
I have a multi threaded C# application which creates files, opens them for processing, then deletes them once finished. This application can expect anywhere from 1 - 100 files to be processed. Somewhat randomly (most likely attributed to the multi threaded nature of the application) I get a sharing violation when I try to delete a file after processing. My gut says, well Vic, you didn't properly close/dispose the file before trying to delete it. And I would go with my gut if it happened for every file, but it doesn't. So, I'm trying to find out where I'm making a mistake. Anyone out there have

Delete Folders and Containing Files

怎甘沉沦 提交于 2019-12-03 20:39:21
问题 I have a really quick question. My program actually downloads a zip file then extracts it onto their desktop. But I need an uninstall feature for it, which is basically deleting multiple folders and containing files. How can I do this in vb.net? 回答1: If all of your folders are contained in a single folder, it should be pretty straight forward. Dim path As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\YOURPATH" System.IO.Directory.Delete(path, True) That will delete

Powershell script to delete files not specified in a list

前提是你 提交于 2019-12-03 19:06:54
问题 I have a list of filenames in a text file like this: f1.txt f2 f3.jpg How do I delete everything else from a folder except these files in Powershell? Pseudo-code: Read the text file line-by-line Create a list of filenames Recurse folder and its subfolders If filename is not in list, delete it. 回答1: Data: -- begin exclusions.txt -- a.txt b.txt c.txt -- end -- Code: # read all exclusions into a string array $exclusions = Get-Content .\exclusions.txt dir -rec *.* | Where-Object { $exclusions