Delete CVS files

January 13th, 2007

When you copy files from a CVS Repository you always get those CVS folders and files.
If you want to delete them and you don’t have access to the CVS Server than you can use this command line:
(updated, as code. If you copied it before 2007-01-16 the quotes weren’t correctly outputed)

for /f "tokens=*" %%i in ('dir /b/a/s CVS*') do @rmdir /q /s "%%i"

I’ve used Aral Balkan’s command from this link though it wasn’t working for me, because my CVS folders were read only and hidden. If your CVS folders aren’t hidden then I recommend you use Aral’s approach which is much faster.

Have fun and batch safely. I will not be held responsible if you delete any unwanted files. :-)
If you feel uncomfortable executing this command, try replacing @rmdir with echo this will give you a glimpse of what you’ll be deleting.
If you find yourself running the script quite often, then you can add the command to your windows explorer right-click context menu by creating a batch file.

Here’s the code for the batch file:

@echo off
echo Deleting CVS folders and files under: %1
REM Open Folder specified by parameter.
cd %1
REM Recursive delete command
for /f "tokens=*" %%i in ('dir /b/a/s CVS*') do @rmdir /q /s "%%i"
echo Done!

Open regedit and goto: My Computer\HKEY_CLASSES_ROOT\Folder\shell\
Create a new entry: “Delete CVS Files” and under that one, create a new key called: command
In Value add the path to the batch file created with %D %L at the end.
Here are some screen shots:

Right button click Context Menu.

Delete CVS File Context Menu

Regedit. Adding the folder right button click:

Regedit Folder Context Menu

*UPDATE*: Comments are closed for this post. I was getting too many spam.

Entry Filed under: Batch Scripts,CVS

Bookmark and Share   Del.icio.us   Technorati

11 Comments

  • 1. pan69&hellip  |  2007-01-24 at 4.28 pm

    I don’t use CVS (subversion instead) but shouldn’t you be making an export from CVS to get your files instead of copying files/folders?

  • 2. Danno&hellip  |  2007-01-26 at 12.27 am

    Yes, but sometimes it’s easier to copy everything. Or if I want to upload something quick and don’t want to export, I just delete the whole CVS files. Anyways, I know it is a bad practice, though I use a lot of times.

    cheers,

  • 3. Henk&hellip  |  2007-02-18 at 5.57 am

    Thanks Daniel, i needed this!

  • 4. monoclast&hellip  |  2007-04-07 at 6.03 am

    I just tried your batch file and noticed it deletes all folders whose names start with CVS, including folders that are not the hidden CVS sub-folders. That’s a bad idea! It should only delete folders whose names are explicitly “CVS”.

    I notice you have:

    for /f “tokens=*” %%i in (‘dir /b/a/s CVS*’) do @rmdir /q /s “%%i”

    Would simply changing it to this fix that problem?:

    for /f “tokens=*” %%i in (‘dir /b/a/s CVS’) do @rmdir /q /s “%%i”

  • 5. emma nzs&hellip  |  2007-07-10 at 10.14 am

    Great stuff!!!

    [url=][/url]

  • 6. Danno&hellip  |  2007-07-11 at 2.56 am

    @monoclast you are right. It will delete every folder starting with CVS. I’ve tried removing the asterix but it doesn’t work :-(

    I don’t think any project will have any folder starting with CVS, but it could be an issue.

  • 7. Chronicles of a Catholic &hellip  |  2007-07-19 at 6.46 am

    [...] http://www.danieltome.com/blog.....cvs-files/ [...]

  • 8. Jm4n&hellip  |  2007-10-24 at 8.15 pm

    In the first code snippet there seems to be a mistake with the double percent signs. You want to use it from the command line, right? http://support.microsoft.com/kb/75634

  • 9. Danno&hellip  |  2007-10-25 at 10.18 am

    Jm4n. Thanks for the tip.
    I use it in a batch file. if you want to run it on the command line you’ll need to take out one percent sign:

    Eg: (for testing)
    for /f “tokens=*” %i in (‘dir /b/a/s CVS*’) do @echo “%%i”

  • 10. Adhi&hellip  |  2008-03-03 at 4.31 am

    Daniel,

    This is amazing!! This is saving huge time.
    Thanks a lot!!

  • 11. arni&hellip  |  2008-03-06 at 8.12 pm

    great work man thx


Most Recent Posts