f



How to delete all files in a directory?

Hello,

How can I delete all files in the directory /usr/me/data  ?

I tried

file delete -force /usr/me/data/*

but that did not work.

Thanks in advance
Nadeem

0
khannu (11)
9/2/2007 7:48:47 AM
comp.lang.tcl 23429 articles. 2 followers. Post Follow

2 Replies
472 Views

Similar Articles

[PageSpeed] 25

foreach file [glob -nocomplain -directory /usr/me/data *] {
    file delete -force $file
}

In 8.5, you could also do

    file delete -force {*}[glob -nocomplain -directory /usr/me/data *]


Another option, at least on Windows (and I assume elsewhere):

    file delete -force c:/usr/me/data

which deletes not only the contents of the directory, but also the
directory itself.  (If needed, you could then recreate the directory
using [file mkdir /usr/me/data].)

0
aric.bills (466)
9/2/2007 8:08:43 AM
khannu@gmail.com wrote:
> I tried
>    file delete -force /usr/me/data/*
> but that did not work.

Aric's message says how to do what you want, but you should be aware of
*why* this all matters. Tcl, unlike bash, does not do glob expansion of
any filename patterns unless explicitly asked to. This is a good thing,
since it means that Tcl scripts aren't derailed by unusual characters
(unlike virtually every bash script ever written!) However, it also
means that when you want globbing you need to do a bit more work and do
the iteration yourself.

Of course, if you're really after squelching the whole directory, you
should just [file delete -force /usr/me/data] but only do that if you do
not care to keep the directory at all. Yes, delete/recreate can work,
but it's easy to lose important aspects like directory attributes if
you're not careful; easier to avoid such situations entirely. :-)

Donal.
0
9/2/2007 3:52:54 PM
Reply:

Similar Artilces:

Delete a directory and all its files and sub-directories?
Hi, Does anyone know of, or have code that will delete a php directory and all its sub directories and files. "unlink" and "rmdir" don't do this. I'd prefer not to use "exec" with a system call but if that's the only way, so be it. I'm using PHP 4.4.4. Thanks, - Dave laredotornado@gmail.com said: > Does anyone know of, or have code that will delete a php directory and > all its sub directories and files. "unlink" and "rmdir" don't do this. > I'd prefer not to use "exec" with a system call but ...

files, directories, files, directories
Hi folks, I've been trying to make a decision and it's driving me crazy. Is a directory a file or is a directory NOT a file but a node? Should I have A) public interface IFile { IFileName FileName; IContent GetContent(); } public interface IDirectory extends IFile { } or B) public interface INode { INodeName NodeName; } public interface IFile extends INode { IContent GetContent(); } public interface IDirectory extends INode { } Method A is nice cause IFile becomes the base "Node" type and you can use names like "IFileName" which sound...

Delete a directory with all sub-directories an files
Hi. I would like to delete a directory. In this directory are other directories an files. So I have to delete this subdirectories an files at first. Now I search a good solution to solve this problem. My first idea was to look in the given directory and if there are subdirectories to look in this directories... Is this the right way? Is there a ready function for this little problem? Or has anybody written a function for it? greetings Dirk Einecke On Sat, 17 Apr 2004 21:53:48 +0200, Dirk Einecke wrote: > I would like to delete a directory. In this directory are other > directori...

Delete empty files in the current directory but not the ones in the sub-directories of current directory.
Hi all, I want to delete empty files in the current directory but not the ones in the sub-directories of current directory. Any hints? Regards. -- ..: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :. Hongyi Zhao <hongyi.zhao@gmail.com> writes: > I want to delete empty files in the current directory but not the ones > in the sub-directories of current directory. Any hints? As usual, ‘find(1)’ is your friend. Read about the ‘-maxdepth’ and ‘-size’ options. -- \ “People come up to me and say, ‘Emo, do people really come up | `\ ...

Tcl script hangs on deleting directory from remote machine while works for files
Hi All, As a part of my tcl script, my requirement is i need to delete contents (i.e. files and directories with my login id) from remote machine. So i am using following code catch {exec /usr/bin/rsh $mac_n {\rm -r ls -lrt /local/test | grep $username | awk {{ print $NF}}}} err1 Now this code deletes files successfully and instantaneously but it hangs while deleting folders. I also tried an alternative solution for deleting files of my login using csh script, but again while executing same script from tcl it hangs. Can some one please help me in figuring out the problem with this code. ...

deleting a line in a file, where file is in directory structure
Hi, I'm trying to deleting a line in a file, where file is in directory structure. I tried this but the output only shows me to screen and do not save tc.info that do not contain "dontrun" find . -name "tc.info" -exec sed '/dontrun/d' {} \; I also tried this #!/bin/sh for x in `find . name tc.info` do y=${x%% tc.info} pushd $y sed '/dontrun/d' tc.info popd done But this is even worst, lots of error... Any suggestions? Thanks. Hi Kelly Check out the following perl code #!/usr/bin/per open(myFile,"te...

delete-file & probe-file on directories
should delete-file and probe-file work on directories? e.g. suppose we have a file "foo" and a subdirectory "bar/". what should (probe-file "foo") (probe-file "foo/") (probe-file "bar") (probe-file "bar/") return? one could argue that the first two invocations should return the same as (truename "foo") and the last two the same as (truename "bar/"). one can also argue that the 2nd and 3rd should return nil - especially if it is possible to have same named files and subdirectories (are there filesystems where fi...

Traversing Directories and Sub Directories and find tcl files
Hi all, I am looking for sample code to find the tcl files in directories and subdirectories. I tried to use -glob option of tcl to find all the directories and sub directories which contain tcl files. Can anyone help me in this regard? I want to know also is there a way that I can transfer the information printed in command console to a output file? On Nov 21, 4:58=A0pm, Pradeep <bubunia2000s...@gmail.com> wrote: > Hi all, > =A0 =A0 I am looking for sample code to find the tcl files in directories > and subdirectories. I tried to use -glob option of tcl to find all the >...

"no such file or directory" when executing tcl file
Hi, new to TCL and hitting a road bump right out the gate. I just installed ActiveTcl 8.5 on my Windows XP SP2 machine. I made the following script and saved it as test.tcl: #!/usr/local/bin/tclsh puts stdout {Hello, Patrick!} When in the TCL command prompt, I type test.tcl and it gives me the error "couldn't execute ".\test.tcl": no such file or directory". I am in the correct directory so I'm pretty lost as to why it is saying this. Here are my exact steps: <open command prompt> H:\workspaces\tcl>tclsh85 % dir Volume in drive H is Data Volume Serial ...

cannot delete file
cannot delete file - http://LongPathTool.com can fix it Do you have error messages?, like : Path too long. Error cannot delete file: cannot read from source file or disk Cannot delete file: Access is denied There has been a sharing violation. Cannot delete file or folder The file name you specified is not valid or too long. Specify a different file name. The source or destination file may be in use. The file is in use by another program or user. Error Deleting File or Folder Make sure the disk is not full or write-protected and that the file is not currently in use. Error Copy...

cannot delete file
cannot delete file - http://LongPathTool.com can fix it Do you have error messages?, like : Path too long. Error cannot delete file: cannot read from source file or disk Cannot delete file: Access is denied There has been a sharing violation. Cannot delete file or folder The file name you specified is not valid or too long. Specify a different file name. The source or destination file may be in use. The file is in use by another program or user. Error Deleting File or Folder Make sure the disk is not full or write-protected and that the file is not currently in use. Error Copy...

tcl-inotify: File & directory level notifications for Tcl. (extension)
This is an announcement for a relatively new Tcl project: tcl-inotify. Tcl-inotify is a Tcl interface to the linux kernel's inotify* service. It provides a Tcl package that enables Tcl scripts to monitor the file system changes at a file and directory level. A large number of file/directory actions can be monitored. A proc is executed asynchronously to notify for changes. * inotify is a Linux kernel subsystem that provides file system event notifications. It was written by John McCutchan with help from Robert Love and later Amy Griffis to replace dnotify. It was included in the ma...

Using File::Find to delete files and directories older than 30 days
I am a Perl beginner and I hve writen this script to remove files older than 30 days, it works well EXCEPT that it leave the empty directories behind, can anyone help me look for empty directories and remove them as well? TIA, Steve #! Perl -w use Strict; use File::Find; $tempdir = "D:\\shared dirs\\temp Public"; find(\&Wanted, $tempdir); sub Wanted { #Do not scan Purchasing or Budget return $File::Find::prune = 1 if $_ eq "Purchasing - Do Not Remove"; return $File::Find::prune = 1 if $_ eq "BUDGET"; # only on files older than 30 days if ( ( -M $_ ) >...

http://DuplicateFilesDeleter.com - This software deletes duplicate files in media collection of any type Duplicate Files Deleter
http://DuplicateFilesDeleter.com - This software deletes duplicate files in media collection of any type Duplicate Files Deleter - automatically with the software to Delete File Duplicates. This software deletes duplicate files in media collection of any type. Want to delete duplicate files? Delete duplicate files everywhere: Delete duplicate files in music collection Automatically delete duplicate files in the photo collection Find and delete duplicate files in any folder Delete duplicate files on the single and multiple hard drives =85 delete duplicate files everywhere All you n...

Web resources about - How to delete all files in a directory? - comp.lang.tcl

Wikipedia:Quick directory - Wikipedia, the free encyclopedia
This page is a handy directory to various locations of interest in Wikipedia. Only dynamic pages should be listed here, no policy pages etc. ...

Telephone directory - Wikipedia, the free encyclopedia
"Phone book" and "White pages" redirect here. For a contact list, see Contact list . For other uses, see White pages (disambiguation) . Subscriber ...

Business Directory Listings: Eight Smart Tips for You to Get Started
If you are considering a business directory listing for your small business, congratulations – you are on the right track. Local SEO, local customers, ...

LinkedIn Lookup iOS app aims to replace your company’s awful intranet employee directory
... continue reading at 9to5Mac . What do you think? Discuss "LinkedIn Lookup iOS app aims to replace your company’s awful intranet employee directory" ...

Atlas Partner Directory Launched
... just for Facebook and Instagram –advertising platform Atlas has one, as well. On that note, Atlas Tuesday introduced the Atlas Partner Directory ...

Slack announces App Directory store
... create more apps for the store, and a new framework called Botkit which should simplify the process of creating apps. The Slack App Directory, ...

The British Library’s ‘Save Our Sounds’ Program Creates Directory of UK Sound Collections
The long-feared deterioration of the world's sound collections is a coming to a head with the British Library's last-ditch initiative called ...

Amazon brings Microsoft users into AWS with Active Directory service
Amazon has launched an AWS Directory Service for Active Directory , a fully managed implementation of Microsoft's authentication and user management ...

Researchers find way to steal Windows Active Directory credentials from the Internet
The technique could enable attackers to attack Windows servers hosted in the cloud

Slack's App Directory proves it's more than just a chatroom
... are about to get a little easier to find and integrate within your team and over 160 of them live within the company's new Slack App Directory. ...

Resources last updated: 2/7/2016 12:07:04 AM