Results 1 to 3 of 3

Thread: Batch Rename from CSV

  1. #1
    Member
    Join Date
    2018-11
    Location
    United States
    Posts
    2
    Login to Give a bone
    0

    Default Batch Rename from CSV

    I've found a half dozen or so variants of this question online and none of them actually reach a conclusion, successful or otherwise.

    I have a few thousand files that I need to rename and update the drawing number on in a title block. Additionally, I need to update continuations in said DWGs, but that will be a separate issue. I've built a crude routine to rename the block attribute based on the file name, but what I'm having difficulty with is the file name itself. I have a CSV file with all the old and new files, but I'm having trouble with the command to execute the rename.

    The CSV is formated:
    FileOld,FileNew
    C:/Directory/FileOld.dwg,C:/Directory/FileNew.dwg
    etc...

    The formatting of FileOld is not consistent, it's made up of 3–6 segments with most segments having varying lengths.
    The formatting of FileNew is consistent, being made of 5 segments with each segment having a specific length and leading 0s if necessary.
    FileNew directly correlates with FileOld.

    My thought is rather than forcing it through VL-FILE-RENAME or a BAT file, I could build on VL-FILE-RENAME and call the arguments from the CSV, but currently I'm being told I'm lacking in arguments.

    I'm currently using function to parse the list from the CSV. This is what I have otherwise.

    Code:
    (defun C:CSV2FILE (/)
    	(setq filelist (open "C:/LISP Directory/filelist.csv" "r"))
    	(setq filedata (read-line filelist))
    	(setq filedata (read-line filelist))
    	(while (/= filedata "EOF")
    		(setq filedata (LM:str->lst filedata ","))
    		(vl-file-rename filedata)
    		(setq filedata (read-line filelist))
    	)
        (close filelist)
    )

  2. #2
    I could stop if I wanted to
    Join Date
    2003-07
    Posts
    348
    Login to Give a bone
    0

    Default Re: Batch Rename from CSV

    The obvious (vl-file-rename filedata) to what filename

    Not looking very hard or tested in any way
    {code]
    (defun C:CSV2FILE (/)
    (setq filelist (open "C:/LISP Directory/filelist.csv" "r"))
    (setq filedata (read-line filelist)) ; dummy to read heading
    (while (setq nline (read-line filelist))
    (setq filedata (LM:str->lst nline ","))
    (vl-file-rename (nth 0 filedata)(nth 1 filedata))
    )
    (close filelist)
    )
    )[/code]

    Be careful if directory has spaces in the name may fail.

  3. #3
    Member
    Join Date
    2018-11
    Location
    United States
    Posts
    2
    Login to Give a bone
    0

    Default Re: Batch Rename from CSV

    Excellent! It worked perfectly.

    (nth # [list]) was exactly what I was looking for.

    I ended up building a BAT file to do it, I knew it had to be pretty straightforward, I just couldn't find the little element to pull it all together. Now I can incorporate this into the full routine for updating these DWGs and not have to do the file rename separate from the rest of the process.

Similar Threads

  1. Batch Rename Tool for Layout Tabs?
    By WhataMaroon in forum AutoCAD Customization
    Replies: 3
    Last Post: 2016-11-06, 03:01 AM
  2. Replies: 0
    Last Post: 2012-09-19, 04:12 PM
  3. Replies: 10
    Last Post: 2008-12-31, 12:29 AM
  4. Batch Rename script needed for renaming files
    By madcadder in forum Software
    Replies: 5
    Last Post: 2007-01-25, 03:01 PM
  5. Free batch program to rename files
    By johan d in forum Software
    Replies: 4
    Last Post: 2006-07-26, 03:23 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •