Tag: Scripts

  • Access denied when creating a folder just deleted

    I have a batch script which remove a folder and re-create it. The command that remove a folder is rd /s/q and the command create folder is mkdir. Recently I see something weird happening, everytime when the folder is deleted and re-created, there is error message Access is denied displayed. However, if I rerun the create folder command laer, it always pass successfully.

    The explanation on http://support.microsoft.com/?id=159199 seems make sense,

    This file is in a state known as pending deletion. This file has been deleted, but there are still handles open to it. NTFS will wait until all handles to this file are closed before updating the index. If an attempt is made to access the file, however, NTFS will deny the attempt. Because the file is listed in the index, but is effectively deleted, you can see the file but you cannot access it.

    The workaround here is add a 60 seconds sleep between the folder deletion and folder creation operation.

  • Delete blank lines from text file

    This note is for a few quick ways to delete all blank lines from a text file.

    1. sed ‘/^$/d’ file > file_new
    2. grep -v "^$" file > file_new
    3. (This is for Notepad++ users) Select all text (shortcut Ctrl+A) and then click Menu TextFX -> TextFX Edit -> Delete Blank Lines

    delete blank lines in notepad++