Rename file using variables... in DOS! - Page 2
Page 2 of 2 FirstFirst 1 2
Results 16 to 30 of 30

Thread: Rename file using variables... in DOS!

  1. #16
    Junior Member grief's Avatar
    Join Date
    Mar 2003
    Location
    Wysox, PA
    Posts
    2
    Originally posted by craigmodius

    I'd also like to give a shout out to Grief for warming up the thread.
    I got your back

  2. #17
    Registered User techleet's Avatar
    Join Date
    Oct 2000
    Location
    San Jose, CA, USA
    Posts
    459
    Originally posted by grief
    I got your back
    What? Did you guys just win the Superbowl or something? The help was great, and I'm VERY grateful, but quit suckin each other's d*cks and get back to work.

    ...

    ...

    KIDDING!!!
    DON'T PANIC

  3. #18
    Registered User
    Join Date
    Apr 2007
    Posts
    3

    Tell me more

    Quote Originally Posted by craigmodius
    I'm not a god I just play one at work.

    I'd also like to give a shout out to Grief for warming up the thread. We were talking at work today about this very same issue of getting the variable to work in NT, and I told him how I posted here and it seems like I have the uncanny ability to kill a thread just by posting on it, so he's got my back
    OK - I have a need to name the file with the date AND time. I hacked at doing a for /f ....('time /t') ... but it failed... Help!
    I need the code you sent out on the date (awesome) and then do the same wi th 'time /t' and concantenate the two to add to the name.

    Thanks in advance

  4. #19
    Driver Terrier NooNoo's Avatar
    Join Date
    Dec 2000
    Location
    UK
    Posts
    31,824
    Welcome to Windrivers jferrel

    Can you confirm that you want to change the data and time as well as the file name... if so, is the date and time to be changed to the same date and time?
    Never, ever approach a computer saying or even thinking "I will just do this quickly."

  5. #20
    Registered User
    Join Date
    Apr 2007
    Posts
    3

    Cool

    Quote Originally Posted by NooNoo
    Welcome to Windrivers jferrel

    Can you confirm that you want to change the data and time as well as the file name... if so, is the date and time to be changed to the same date and time?
    OK - I was testing his code (the code above with the 'for /F' command) , and was able to do this:
    copy c:\filename.txt i:\filename_042607.txt
    (with success)

    What I want to do is append the 'time' of the copy as well, to the filename; this way I can make multiple copies of the original file in one day and they will remain unique.

    I want endup with this:
    copy c:\filename.txt i:\filename_042607_1:35PM.txt
    (with success)

    I duplicating the code and parsing ('time /t'), but found I am a loser and can't get it right.

    HELP!!!!

  6. #21
    Driver Terrier NooNoo's Avatar
    Join Date
    Dec 2000
    Location
    UK
    Posts
    31,824
    Well you can't have a ":" in the filename....
    Never, ever approach a computer saying or even thinking "I will just do this quickly."

  7. #22
    Registered User
    Join Date
    Apr 2007
    Posts
    3
    Quote Originally Posted by NooNoo
    Well you can't have a ":" in the filename....
    OK...I'll try using delims=: and parse out the time numbers and then concantenate... I'll let you know...

  8. #23
    Registered User
    Join Date
    Sep 2007
    Posts
    1
    You all seem like really smart folks..... (notice the buttering up....). I'm struggling with a problem that a newer version of AutoCAD is throwing at me. We're jumping from Release 14 (around 1998) up to AutoCAD 2007. I Have a batch process to save plot files on our file server. This version of AutoCAD insists on appending -Layout1 to the filename. So whereas we currently have 4000+ plot files that look like this: tw184892.plt we are now forced to use plot files that look like this tw184892-Layout1.plt. The plot files are being called from a database, to print at the bottom of a sheet with barcode information on it. So, as part of my batch file save process, I'd like to save the plot file without the -Layout1 in the name. Is there a way to rename the plot file at the dos level (really WinXP, not DOS), taking into account that the current file name that needs to be renamed could be:

    my-Layout1.plt
    myfile-Layout1.plt
    myfile0005-Layout1.plt

    So I can't just strip off the first X number of characters. I could strip out the last 8 characters of the file name. Any thoughts? This is the first part of the process:


    F:
    CD \OPEN\DWG
    DIR /B /L *.PLT | FIND ".plt" > PLT.BAK
    COPY C:\ACAD2007\SUPPORT\DO.DAT+PLT.BAK DO.BAK > NUL
    COPY C:\ACAD2007\SUPPORT\DOE.DAT+DO.BAK DO.BAT > NUL
    CALL DO.BAT

    By the end of this, I end up with DO.BAT which looks like this:

    IF NOT %1! == ! SET DWG=%1
    IF NOT %DWG%! == ! C:\VEDIT\VPW -X CLEANPLOT.VDM %DWG%
    IF NOT %DWG%! == ! MOVE %DWG% F:\OPEN\PLT\
    IF NOT %DWG%! == ! EXIT
    DO tw4841eb-layout1.plt
    


    So, I could easily put some kind of a RENAME function in there, but I'm not sure about how to go about doing the last 8 char? Any thoughts?

    Mick

  9. #24
    Driver Terrier NooNoo's Avatar
    Join Date
    Dec 2000
    Location
    UK
    Posts
    31,824
    Welcome to Windrivers Mickth

    Just thinking round the problem... what happens if you end up with a layout-2? Is it that the database column width cannot handle the new filename length? If so, just create a new table, with the appropriate widths, populate it from the old table, drop the old table, rename the new table and then never have to bother about it again.

    I say this because you are introducing another processing step which could result in a point of failure and this processing has to take place at least daily whereas a simple change to the database takes 5 minutes once.
    Never, ever approach a computer saying or even thinking "I will just do this quickly."

  10. #25
    Driver Terrier NooNoo's Avatar
    Join Date
    Dec 2000
    Location
    UK
    Posts
    31,824
    Oh, if you want to do the batch file thing anyway you need to remove the substring -layout1

    set str=tw123456-layout1.plt
    set str=%str:-layout1 =%

    more info here
    Never, ever approach a computer saying or even thinking "I will just do this quickly."

  11. #26
    Registered User
    Join Date
    May 2010
    Posts
    2

    Needs Help

    I am trying to ren a whole lot of files using for /r %i in (*.*) do ren "%i" "%i.tif"
    and get a syntex error any help?

  12. #27
    Registered User CeeBee's Avatar
    Join Date
    Nov 2002
    Location
    USA
    Posts
    2,494
    Quote Originally Posted by grantl View Post
    I am trying to ren a whole lot of files using for /r %i in (*.*) do ren "%i" "%i.tif"
    and get a syntex error any help?
    Are you using this syntax in a batch file? If yes you'll need to double the % sign... so:
    for /r %%i in (*.*) do ren "%%i" "%%i.tif"
    Protected by Glock. Don't mess with me!

  13. #28
    Registered User
    Join Date
    May 2010
    Posts
    2
    I tried that, recieved a sytex error on the command.

  14. #29
    Registered User CeeBee's Avatar
    Join Date
    Nov 2002
    Location
    USA
    Posts
    2,494
    Try
    for /r %i in (*.*) do ren "%i" "%~nxi.tif"
    You may not specify the full path for the destination file while renaming, just the new name
    %~nxi will expand the %i variable to name and extension (ex c:\temp\file1.txt -> file1.txt)
    Edit: of course if placed in a batch file you have to use %%i instead of %i
    Protected by Glock. Don't mess with me!

  15. #30
    Registered User
    Join Date
    May 2010
    Posts
    1
    Quote Originally Posted by mickth View Post
    You all seem like really smart folks..... (notice the buttering up....). I'm struggling with a problem that a newer version of AutoCAD is throwing at me. We're jumping from Release 14 (around 1998) up to AutoCAD 2007. I Have a batch process to save plot files on our file server. This version of AutoCAD insists on appending -Layout1 to the buy viagra uk filename. So whereas we currently have 4000+ plot files that look like this: tw184892.plt we are now forced to use plot files that look like this tw184892-Layout1.plt. The plot files are being called from a database, to print at the bottom of a sheet with viagra soft barcode information on it. So, as part of my batch file save process, I'd like to save the plot file without the -Layout1 in the name. Is there a way to rename the plot file at the dos level (really WinXP, not DOS), taking into account that the current file name that needs to be renamed could be:

    my-Layout1.plt
    myfile-Layout1.plt
    myfile0005-Layout1.plt

    So I can't just strip off the first X number of characters. I could strip out the last 8 characters of the file name. Any thoughts? This is the first part of the process:


    F:
    CD \OPEN\DWG
    DIR /B /L *.PLT | FIND ".plt" > PLT.BAK
    COPY C:\ACAD2007\SUPPORT\DO.DAT+PLT.BAK DO.BAK > NUL
    COPY C:\ACAD2007\SUPPORT\DOE.DAT+DO.BAK DO.BAT > NUL
    CALL DO.BAT

    By the end of this, I end up with DO.BAT which looks like this:

    IF NOT %1! == ! SET DWG=%1
    IF NOT %DWG%! == ! C:\VEDIT\VPW -X CLEANPLOT.VDM %DWG%
    IF NOT %DWG%! == ! MOVE %DWG% F:\OPEN\PLT\
    IF NOT %DWG%! == ! EXIT
    DO tw4841eb-layout1.plt
    


    So, I could easily put some kind of a RENAME function in there, but I'm not sure about how to go about doing the last 8 char? Any thoughts?

    Mick


    Thanks. Now it works
    Last edited by MarCn; June 1st, 2010 at 08:32 AM.

Bookmarks

Posting Permissions

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