Bulk renaming files

This may be similar to my other post, except that we have come to grips with the reality that (at least for now) we won't be able to change the names of versioned files.

I have about 15000 files to rename, and I would like to automate the process to save time, and to avoid errors inherrent with tedious processes.

So far the only API function I have found that will rename a document is aaApi_RenameDocumentDlg, which doesn't really rename the document it just pops open the dialog so that the user can renmame it.

Am I missing something?  Also any tips on how to go about iterating or searching through the files in my document library would be appreciated.

TIA, John

  • John,

    Attempting to rename a file in ProjectWise could fail for a number of reasons.  You could simply try and then check the error.  Take a look at aaApi_GetLastErrorId() and the related functions.  You might want to try this approach just to help you determine why you cannot rename this particular document's file.  You cannot rename files of previous document versions, so I would check and verify that the document you are trying to modify is in fact the "Active" document.  Check the documentation for the document property DOC_PROP_ORIGINALNO.

    You can only rename a file if the active document is checked in and the user has write access to the document and file.  Also, "Final status" will also keep you from being able to rename a file.  You can examine a document properties by selecting it into a document buffer and then using aaApi_GetDocumentNumericProperty() or aaApi_GetDocumentStringProperty().

    Instead of selecting the document into a buffer and using the "Get" functions, you can also use convenience functions such as aaApi_IsDocumentCheckedIn() to check if a document is checked in or not.   You can check if you have write access to the file with aaApi_GetDocumentAccess() although I'm not sure if this will actually tell if you have write access to the file as you can have write access to the document, but not the file.  For that level of detail, you may have to use aaApi_SelectAccessControlItems() and then aaApi_GetAccessControlItemNumericProperty() and then take a look at ACCE_PROP_ACCEMASK.

     HTHs

  • Things are going pretty well.

    I am actually able to perform the rename, but need to make my program more elegant for IT QA.  I am making one function that does not rename the files, but just tells the user what would happen. Then the user can call the other function to actually perform the rename operation.

    Is there a way to tell if a particular file is locked and cannot be renamed.  I have found aaApi_IsDocumentCheckedIn, but a versioned document is checked in and still cannot be renamed.

    Thank-you

    John

  • John,

    An easy way to implement a Document Command that will allow you to process a set of selected documents is to use a MRR menu file.  Search the ProjectWise SDK help file for "ProjectWise Menu Editor" and then scroll down until you find this prototype:

    The prototype for a Document Command, short parameter list (standard dll):

    int WINAPI CustomDocumentCmd
    (
    unsigned int count,
    long*  pProjects,
    long*  pDocuments
    );

    Make sure that you export this function as extern "C" if you are using C++.

    count will contain, of course, a count of the documents selected.  The other two parameters are pointers to arrays containing the documents' Project and Document ID's.  You can then loop through the arrays and process each document. 

    HTHs

  • How do I get a (list) of the currently selected documents?

    I tried the following, but it always gives me a count of 5, now matter how many documents are selected.

    Thanks, John

    my_doc_list = aaApi_GetActiveDocumentList();

    int num_docs = aaApi_DocListNavigatorGetCount (my_doc_list);

    wsprintf(temp_wstr, L"Number of files: %d", num_docs);

    MessageBox (HWND_TOP, temp_wstr, L"Caption", 0);

  • Thank-you very much!

    I will let everyone know how it goes.

    John