Command-Line question. Delete all but particular folders

Hello. I need to create a batch file that will delete all folders within the "Users" folder except for the Administrator and Administrator.domainname.
Can anyone help?
Thanks

You could try something along the lines of
FOR /F "tokens=*" %%G IN ('DIR /B /A:D c:\test') DO if not "%%G" == "test2" if not "%%G" == "test3" rd /s /q "c:\test\%%G"
but if you do, you may also delete
c:\Users\Public
c:\Users\Default         (a hidden folder)
c:\Users\All Users       (a system folder)
c:\Users\Default User (a system folder)
Which may be regrettable. If you want an example of what happens then, try reading
http://superuser.com/questions/219082/accidentally-deleted-user-profiles-on-windows-7-cant-log-on-with-other-users

Similar Messages

  • Which command line to delete all ACL permissions ?

    Hi,
    I would like to clean all old ACL permissions in folders and sub-folders, to put on the main share folder the right ACL's and distribute them.
    It seems it's impossible in Server Admin interface. Which is the command line able to do that ?
    I believe it's something like chmod ???
    Thanks for your response.
    Patrick

    chmod -N is the command to remove ACLs. -R runs recursively, therefore to recursively remove all ACLs from a directory tree:
    sudo chmod -R -N /path/to/dir

  • Having problem deleting all but one particular mail from the iPhone 4S mail inbox. I can delete mail either by the trash can or using edit, selecting the mail message and deleting.  However there is this one mail message that will not go away. Any ideas?

    I am having a problem deleting all but one particular mail message from my inbox. I delete by either using the trash can icon for individual mail, or using edit, selecting the mail message (s) and clicking delete.  However there is this one mail message that will not go away regardles of what I do including deleting all from the trash.  Any ideas?

    I get that every once in a while on my 3GS, and that's what I do to get rid of it. Probably not a bad idea to power down the phone every so often, anyway, gets rid of any crud waiting to cause a bug.
    Glad to hear that it worked for you.

  • 1st Gen Ipod touch - 'updated' library by deleting all but newest

    Hi all. A couple of days ago I probably hit the capacity on my 16gb 1stG touch, after downloading a couple of podcasts. It 'updated' my music and video library, deleting all but the newest items.
    I'd like to know if my old stuff is still on there - I haven't synced it to a computer since my computer crashed, though we do have carbonite so not all is lost. Was just hoping I wouldn't have to go through all that - that the music and video would still be in there somewhere!
    I have used the Touch Copy software before and have put this same question in to their support. Any help / advice would be appreciated! Thank you in advance!

    I've had the same thing happen multiple times over the last year. It always follows downloading podcasts through iTunes (not through a podcast app).
    I've only ever fixed it by re-syncing to iTunes. However, I'm away from my computer and no don't have access to any of my music or audiobooks.
    I'd love to know how to fix it from the iPod only. I've just power cycled and reset (hold wake/home buttons til it reboots) with no impact.

  • Delete command is not deleting all rows

    Hi All,
    Database version 10.2.0.2
    Delete command is not deleting all rows and deleting some subset of rows which it should delete, ever time I delete and do the roll back, next time it will delete some random rows, count is different everytime with in the range but not complete in anyway. see the following -
    select count(*) from test where evt_id in (select evt_id from test1);
    COUNT(*)
    27105
    delete from test where evt_id in (select evt_id from test1);
    16045 rows deleted.
    select count(*) from test where evt_id in (select evt_id from test1);
    11060
    rollback;
    Againg the same procedure -
    select count(*) from test where evt_id in (select evt_id from test1);
    COUNT(*)
    27105
    delete from test where evt_id in (select evt_id from test1);
    14320 rows deleted.
    select count(*) from test where evt_id in (select evt_id from test1);
    COUNT(*)
    12785
    why its not deleting all the 27k rows in one shot? Is there any bug related to that?
    Thanks
    Abhinav

    Odd that what looked like identical statements produced different results, both the counts and the deletes. The most likely cause of that is your data is changing - as Fahd suggested perhaps a simultaneous load taking place.
    The delete issue is probably not due to a bug. Possible but unlikely.
    If any evt_id values are NULL they won't be deleted with the subquery - a NULL in test.evt_id will never match a NULL in test1.evt_id.
    Have you tried alternative subqueries - a correlated EXISTS subquery for instance?

  • I want to sell my iMac: delete all but keep original MS office pack (or re-install?)

    I want to sell my iMac: delete all but keep original MS office pack (or re-install?)
    BR Pia

    We are having problems with the forum software (I can't see any new thread), so you are very lucky if somebody reads your question. Personally, the forum are near unusable for me now.
    Respecting to that question, you want to delete everything but leave Office. Is this correct? If so, you will have to contact with Microsoft to see if it's legal to sell your Mac with Office installed > http://www.microsoft.com/mac/support I would not sell the Mac with Office installed.
    To delete everything, you will have to erase the drive and reinstall OS X. Normally, you should turn off the Mac after reinstalling OS X, but in this case, the new owner won't have Office. On the contrary, if you install Office, the owner will have to use the Mac with your settings, so there will be other steps to follow

  • How do i delete all my music folders?

    I have just got a new laptop and the people in store moved my music from my old laptop to my new one. They managed to create 2 of everything and now I can't sort it out. I have tried uninstalling apple to reinstall it but it just saved all my previous libraries so I have the same problem! Can i delete all my music folders and start again from scratch? Please help? I am not very IT literate so need all the help I can get?

    These are two possible approaches that will normally work to move an existing library to a new computer.
    Method 1
    Backup the library with this User Tip.
    Deauthorize the old computer if you no longer want to access protected content on it.
    Restore the backup to your new computer using the same tool used to back it up.
    Keep your backup up-to-date in future.
    Method 2
    Connect the two computers to the same network. Share your <User's Music> folder from the old computer and copy the entire iTunes library folder into the <User's Music> folder on the new one. Again, deauthorize the old computer if no longer required.
    Both methods should give the new computer a working clone of the library that was on the old one. As far as iTunes is concerned this is still the "home" library for your devices so you shouldn't have any issues with iTunes wanting to erase and reload.
    I'd recommend method 1 since it establishes an ongoing backup for your library.
    If you have an iOS device that syncs with contact & calendar data on your computer you should migrate this information too. If that isn't possible create a dummy entry of each type in your new profile and iTunes should offer to merge the existing data from the device into the computer, otherwise the danger is that it will wipe the information from the device.
    If your media folder has been split out from the main iTunes folder you may need to do some preparatory work to make it easier to move. See make a split library portable.
    Should you be in the unfortunate position where you are no longer able to access your original library, or a backup of it, then see Recover your iTunes library from your iPod or iOS device for advice on how to set up your devices with a new library with the maximum preservation of data. If you don't have any Apple devices then see HT2519 - Downloading past purchases from the App Store, iBookstore, and iTunes Store.
    tt2

  • QT Command Line Question

    I am looking for a script which I can convert movies through a simple line of code while being able to adjust Quality, file types to convert to, Frame Rates ...
    Pretty much all that Quicktime Pro can do.
    does anyone have an idea of where I can start?

    Try starting by opening the Script Editor in the /Applications/AppleScript folder, loading the QuickTime Player's AppleScript dictionary, and working until you create a script which does what you want. If you succeed in doing this, you can then create a command line method of converting the movies if you want to; post back for further assistance.
    There are a few pure command line tools for QuickTime, but all the ones I found can only play QuickTime files without having the capability to modify anything.
    (13221)

  • My iPhone 5S is using 2.5GBs of storage for the camera roll.  I deleted all but 190 photos and this did not change.  My other devices cannot backup to iCloud due to the volume on my iPhone.  Any ideas?

    My iPhone 5S is using 2.5GBs of storage for the camera roll.  I deleted all but 190 photos and this did not change.  My other devices cannot backup to iCloud due to the volume on my iPhone.  Any ideas?

    Try turning off the Camera Roll option in Settings>iCloud>Backup & Storage>Manage Storage>Your device. Then turn it back on again.
    Cheers,
    GB

  • HT1923 This article contains the only thing that worked for me.  I also had to sign out of iCloud and uninstall it.  Then I had to delete all files and folders from all of those applications that were under Program Files, Program Files x86, and Users.

    This article contains the only thing that worked for me.  I also had to sign out of iCloud and uninstall it.  Then I had to delete all files and folders from all of those applications that were under Program Files, Program Files x86, Program Data and Users.  My iPhone 4 will now sync with iTunes both in its USB-connected  mini dock and over Wi-Fi.  It's unfortunate (negligent programming on the part of Apple?) that the upgrade to iTunes 11 did not remove all of those files as part of the upgrade process. 

    I am having the same issue....Same address for years - same as USPS - I tried 5 times (3 macs and 2 iPhones) and now i have 5 CHARGES for 1.00 each on my credit card. I took the credit card info off so they don't charge me anymore. How can they charge me yet still not allow me to download free updates and say I have an invalid address? I'm sure I will spend weeks or months trying to get a credit out of these incompetent idiots.

  • When uploading my email account it also uploaded over 6,000 emails that are on the aol server from over the years, how can I delete all but recent ones?

    when uploading my email account it also uploaded over 6,000 emails that are on the aol server from over the years, how can I delete all but recent ones?

    Unfortunately, there is no easy way.  Delete just as you would any other message that you don't want.  It's probably just as well that there is no universal deletion capability.  I can see many of us committing a major "oops."

  • Time Machine deletes all but latest two backups

    Hello,
    Today I was backing up my macbook, with about 38 GB of space left on my harddrive, and Time Machine deletes everything but the latest two backups (from Feb 2012 to May 2012).... I had things on there from 2009. TM preferences now says I have 27 GB of free space, after the latest backup. I didn't have anything big enough on my computer to be backed up that justified deleting years of data, over 200 GB, in order to compensate for the new data that had to be backed up. Is there any way to recover the files that were erased off of my external hard-drive that were deleted during Time Machine's semi-routine back up?
    Thank you

    Sebastian Kuhn wrote:
    Is there no way to set up Time Machine such that it will ASK before destroying a (potentially valuable) "old" backup
    That's how it worked at first, on Leopard.  But many users either didn't understand it, or never got around to doing anything, so had no backups at all when disaster struck.  It was fairly common, so Apple changed it with Snow Leopard.
    Why does Apple assume that it is always the OLDEST backup (which will be hardest to retrieve) that people would be willing to loose?
    That's usually correct.  Time Machine is not a traditional archive-type app;  if you need archives, make archives.
    If you frequently need things from your backups, you may have a deeper problem.  But most likely, you just need a larger backup drive. 
    That all applies to the vast majority of users -- they have a single internal HD with less than 1 TB of data, so a 2 TB backup drive is ok, 3 TB large enough for most everybody.
    If that's not enough for your setup, you probably need a different strategy anyway.  You may have some data that changes frequently and should be backed-up hourly by Time Machine, plus something like a large media drive that's best backed-up only once a day or so by a different app, such as one of the "cloning" products. 
    there should be the option to exclude different items when backing up to different disks. Is there?
    No.  Apparently Apple wants to keep it as simple as possible, with  few options that may confuse some folks, so instead of making a decision, they do nothing  (that's not just Time Machine, either).  Remember, most of the folks using Time Machine have never used any backup app at all. 
    Apple's resisted all suggestions (and there have been many) for things like the ability to limit the size or age of backups, reduce the 10-day warning when no backup has been done, etc.  Like it or not, that's Apple's approach to pretty much everything -- streamlined, simple, easy to use.  Very successful for the majority.
    Is there any workaround other than the cumbersome procedure of turning Time Machine off, and under "options" re-select the correct set of folders to exclude every time I move from one disk to another? Not exactly what I would call a user-friendly interface...
    Best of course, is get a larger disk.  Is your data worth the price of a 2 TB disk? 
    There are some elaborate workarounds involving automatically swapping destinations and exclusions, but they're very "iffy" as they do things that TM (and OSX) don't anticipate so don't react well to.
    Effective with Lion, however, there's a new tmutil command that in theory would allow you to write an AppleScript to set a destination, add or remove exclusions and run a backup.  Many things could go wrong, of course, but I know of no way to detect which destination is available. 
    Much safer, easier, and more reliable to get a larger drive (or better strategy).

  • How to delete all files and folders (with files) in IsolatedStorage.

    Hi awesome programmer:-) The code I have to clean up the local folder doesn't work properly so I won't even bother posting it here. I basically want to have a "master reset" option to remove all new created files and folder in the local folder.
    Can you give me simple code to remove all files/folder so the app goes back to the state it was when the user installed it for the first time? Thanks in advance. ps I were able to delete a directory(-ies) with this method:
    private async void DeleteDirectory(string directoryName)
    try
    var folder = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFolderAsync(directoryName);
    if (folder != null)
    await folder.DeleteAsync();
    this.Dispatcher.BeginInvoke(delegate()
    txtUpdateFeed.Text = "Folder < " + directoryName + " > deleted.";
    catch (Exception ex)
    this.Dispatcher.BeginInvoke(delegate()
    txtUpdateFeed.Text = "Delete Directory << " + directoryName + " >> Error: " + ex.GetBaseException().Message.ToString();
    It seems to work, I have not tested with all conditions though. Anyway let me put up the code so you can see I have been trying: This is to delete everything but not all files are deleted:
    private void WipeAllData(bool bln)
    try
    txtUpdateFeed.Text = "Removing files...";
    if (bln)
    txtUpdateFeed.Text = "Removing folders...";
    //Delete videos directory
    DeleteDirectory("videos");
    //Delete pictures directory
    DeleteDirectory("pictures");
    txtUpdateFeed.Text = "Folders removed.";
    //Delete the rest of the files
    var iso = IsolatedStorageFile.GetUserStoreForApplication();
    foreach (string name in iso.GetFileNames())
    iso.DeleteFile(name);
    BtnWipeAllData.Content = "Wipe All Data";
    VideoCameraPowerValue = "on";
    BtnVideoCameraPower.Content = "Video Camera: ON";
    PhotoCameraPowerValue = "on";
    BtnPhotoCameraPower.Content = "Photo Camera: ON";
    txtUpdateFeed.Text = "Files removed successfully.";
    catch (Exception ex)
    MessageBox.Show("Wipe All Data Error:\n" + ex.Message.ToString());
    Why isn't all files being deleted?

    Hi Clint William Theron,
    Based on your descriptions, I know that when you run the above code, it does not delete all the files, then have you checked that which kinds of files or in which folder the files can not been deleted?
    Besides, if you want to let the app go back to the state it was when the user installed it for the first time, then an easy way is to uninstall and reinstall it.
    Best Regards,
    Amy Peng
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Deleting all inherit sub-folders permission and reassigning to specific group

    Hi,
    i am trying to assign sub-folders level permission in sharepoint document library. Want to delete all previous inherit permission first and then assign  sub-folders permission to specific group. i am having problem with following code, cannot make a
    call to the function. Could you tell me what should i modify the code to work properly.
    Thanks in advanced
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.SharePoint;
    namespace ManageFolderLevelPermission
        class FolderLeverPermission
            static void Main(string[] args)
                //Connect to Sharepoint Site
                SPSite oSPSite = new SPSite("http://nyc01d1sp:8080/");
                //Open Sharepoint Site
                SPWeb web = oSPSite.OpenWeb("/hr/DI/");
                //Get the Sharepoint list item for giving permission
                foreach(SPFolder folder in web.GetFolder("http://nyc01d1sp:8080/hr/DI/docs/").SubFolders);
                setPermissions();
            private static void setPermissions(SPFolder folder,SPSite oSPSite, SPWeb web)
                SPGroupCollection spc = web.SiteGroups;
                //Break the role inheritance in order to assign individual rights on folders
                if (!folder.Item.HasUniqueRoleAssignments)
                    folder.Item.BreakRoleInheritance(true);
                while (folder.Item.RoleAssignments.Count > 0)
                    try
                        folder.Item.RoleAssignments.Remove(0);
                    catch (Exception)
                        break;
                //Role Assignment For the Current User
                SPUser CurrentUser = SPContext.Current.Web.CurrentUser;
                SPGroup group = spc["GroupName"];
                SPRoleAssignment roleAssignment = new SPRoleAssignment((SPPrincipal)CurrentUser);
                roleAssignment.RoleDefinitionBindings.Add(web.RoleDefinitions.GetByType(SPRoleType.Administrator));
                folder.Item.RoleAssignments.Add(roleAssignment);
                //Role Assignment for the Group "Contentteam - Management"
                roleAssignment = new SPRoleAssignment((SPPrincipal)group);
                roleAssignment.RoleDefinitionBindings.Add(web.RoleDefinitions.GetByType(SPRoleType.Administrator));
                folder.Item.RoleAssignments.Add(roleAssignment);            
                oSPSite.AllowUnsafeUpdates = true;
                folder.Item.Update();

    Hi Hemendra,
    Thanks for your reply. Actually i am trying to do two things here. First i am creating sub-folders using following code. And then trying to assign individual group permission on these sub-folders using following Powershell script. Now problem is when i am
    creating sub-folders, its also inheriting all the parent permission. Lets say i have customer folder name "Pepsi" and it has 4 sub-folders (like Account Management, Legal Drafts, Executed.. etc) . Now i want to assign individual group permission to each Sub-folder
    but root folder (Pepsi) should remain all the parent permissions. i did try to remove the permission first and then assigned permission to sub-folders. i was able to assign individual group permission to sub-folders but problem is, its also assigning Limited
    Access to the root folder. so basically i cannot see the folder as the root folder has limited access. Please let me know how can achieve that.
    using System;
    using System.Collections.Generic;
    using Microsoft.SharePoint;
    namespace Add_SubFolders
        class CreateFolders
            static void Main(string[] args)
                var foldersList=new List<string>();
                SPSecurity.RunWithElevatedPrivileges(delegate()
                    try
                        using (SPSite site = new SPSite("http://nyc01d1sp:8080/"))
                            using (SPWeb web = site.OpenWeb("/lel/DB/"))
                                web.AllowUnsafeUpdates = true;
                                    foreach (SPFolder folder in web.GetFolder("http://nyc01d1sp:8080/lel/DB/docs").SubFolders)
                                        if (folder.Url.ToString() != "/docs/Forms" && folder.Url.ToString() != "/docs/")
                                            foldersList.Add(folder.Url);
                                            SPFolder subFolder = web.GetFolder(folder.Url);
                                            Console.WriteLine("SubFolder is creating.....");
                                            subFolder.SubFolders.Add("Account Management");
                                            subFolder.SubFolders.Add("Legal Drafts");
                                            subFolder.SubFolders.Add("Executed");
                                            subFolder.SubFolders.Add("Sales");
                                        folder.Update();
                                        Console.WriteLine("SubFolder has been created");
                                    web.AllowUnsafeUpdates = false;
                    catch (Exception ex)
                        ex.Message.ToString();
      Power Shell Script to assign individual group to specific folders:
    Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
      #$site = new-object Microsoft.SharePoint.SPSite("http://nyc01d1sp:8080/lel/DB/")
      #$site = Get-SPSite ("http://nyc01d1sp:8080/")
      $web= Get-SPWeb("http://nyc01d1sp:8080/")
      #$web = $site.OpenWeb()
      function GrantGroupPermission($groupName)
       [Microsoft.SharePoint.SPGroupCollection]$spgroups = $web.SiteGroups
       [Microsoft.SharePoint.SPGroup]$spgroup = $spgroups[$groupName]
       Write-Host $spgroup.Name -ForegroundColor Red
       $sproleass=new-object Microsoft.SharePoint.SPRoleAssignment([Microsoft.SharePoint.SPPrincipal]$spgroup)
       $folder.BreakRoleInheritance("true")
       $sproleass.RoleDefinitionBindings.Add($web.RoleDefinitions["Contribute"])
       $folder.RoleAssignments.Add($sproleass);
       Write-Host "Permission provided for group ", $groupName
      $doclib=[Microsoft.SharePoint.SPDocumentLibrary]$web.Lists["Shared Documents"]
      $foldercoll=$doclib.Folders;
      foreach($folder in $foldercoll)
       Write-Host $folder.Name
       if($folder.Name.Equals("Account Management"))
        GrantGroupPermission("Test Group")
       if($folder.Name.Equals("Executed"))
        GrantGroupPermission("Legal Group")
       if($folder.Name.Equals("Legal Drafts"))
        GrantGroupPermission("Legal Group")
       if($folder.Name.Equals("Sales"))
        GrantGroupPermission("Sales Group")
      Write-Host "Completed...."
      $web.Close()
      $web.Dispose()
      #$site.Dispose()

  • Command line questions....

    I really have two questions here.
    First, I have a small server that is very similar to this one I pulled off a tutorial:
    public class MyServer{
    // A bare-bones example: exception handling omitted.
       public static void main( String args[] ){
          ServerSocket serv;
          serv = new ServerSocket( 5150 );
          while ( true ) {
             Socket s;
             s = serv.accept();          // Wait for a connection
             handle_connection( s );  // Got one, now do something!
            s.close();
    } When I run this program from the command line it goes into an infinite loop readily accepting connections.
    For the most part, this is what I want. But how do I gracefully exit the program? Simply closing the command window seems drastic, not to mention the list of exceptions it throws.
    Second question: Once I run my program, is there a way I can close the command line window and log off the computer without killing my program?
    thanks.
    (Running on NT)

    How do you stop the program? You write another program that connects to the same socket and sends a message that both programs agree means "Shutdown". When the server receives this message, it shuts down nicely.
    Now you want to run it as an NT service? I've seen people post links to a third-party package that can run a Java class as an NT service; I didn't note the link but you could probably find it by searching the forums.

Maybe you are looking for