Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: getting stuck with rename scripts  (Read 2704 times)

0 Members and 1 Guest are viewing this topic.

Kizzie

    Topic Starter


    Newbie

    getting stuck with rename scripts
    « on: December 13, 2009, 07:05:09 AM »
    I am trying to create a .bat that will move, rename (filename - date) and zip a number of files.

    i have got so far and the files move successfully but the rename doesnt seem to work - i dont get any error messages back though.

    also i cannot find a command which will create a zipped folder with the new files in it. i have tried wzzip, pkzip and zip but none are recognised commands.

    does anyone have any suggestions?

    MOVE /-y c:\Responsebackup\* c:\responsearchive\

    set mm= %Date:~3,2%
    set dd = %Date:~0,2%
    set yy = %Date:~8,2%
    for %%i in (c:\Responsearchive.*) do ren %%i %%dd-%mm-%yy.txt


    Many thanks

    Helpmeh



      Guru

    • Roar.
    • Thanked: 123
      • Yes
      • Yes
    • Computer: Specs
    • Experience: Familiar
    • OS: Windows 8
    Re: getting stuck with rename scripts
    « Reply #1 on: December 13, 2009, 07:55:13 AM »
    There are different types of variables. There are FOR LOOP variables that look like %%a or %%b , and there are also regular variables that are %variablename%. When you define dd, mm and yy, you have to wrap them in % because they are regular variables.
    Where's MagicSpeed?
    Quote from: 'matt'
    He's playing a game called IRL. Great graphics, *censored* gameplay.

    billrich



      Rookie

      Thanked: 1
      Re: getting stuck with rename scripts
      « Reply #2 on: December 13, 2009, 12:35:00 PM »
      C:\batch>type  kizzie.bat

      Code: [Select]
      @echo off
      setlocal enabledelayedexpansion

      copy   c:\batch\backup\* c:\batch\archive\

      echo Date = %date%

      set mm=%Date:~4,2%
      echo mm =%mm%

      set dd=%Date:~0,2%
      echo dd =%dd%

      set yy=%date:~10,4%

      echo yy =%yy%

      dir c:\batch\archive\


      dir /b c:\batch\archive\* >  arc.txt


      for /f "delims=" %%a in (arc.txt)do (ren "c:\batch\archive\%%a" "%dd%%mm%%yy%.txt" )

      dir c:\batch\archive\

      OUTPUT:

      C:\batch>
      C:\batch> kizzie.bat
      c:\batch\backup\liz1212.txt
      c:\batch\backup\liz1213.txt
              2 file(s) copied.
      Date = Sun 12/13/2009
      mm =12
      dd =Su
      yy =2009
       Volume in drive C has no label.
       Volume Serial Number is F4A3-D6B3

       Directory of c:\batch\archive

      12/13/2009  06:01 PM    <DIR>          .
      12/13/2009  06:01 PM    <DIR>          ..
      12/13/2009  12:25 PM                13 liz1212.txt
      12/13/2009  12:25 PM                13 liz1213.txt
      12/13/2009  12:25 PM                13 Su12 2009.txt
                     3 File(s)             39 bytes
                     2 Dir(s)  305,513,332,736 bytes free

       Directory of c:\batch\archive

      12/13/2009  06:01 PM    <DIR>          .
      12/13/2009  06:01 PM    <DIR>          ..
      12/13/2009  12:25 PM                13 liz1212.txt
      12/13/2009  12:25 PM                13 liz1213.txt
      12/13/2009  12:25 PM                13 Su12 2009.txt
                     3 File(s)             39 bytes
                     2 Dir(s)  305,513,332,736 bytes free
      C:\batch>

      P.s. ren has duplicate problems
      « Last Edit: December 13, 2009, 05:08:42 PM by billrich »

      billrich



        Rookie

        Thanked: 1
        Re: getting stuck with rename scripts
        « Reply #3 on: December 13, 2009, 08:12:21 PM »
        I am trying to create a .bat that will move,copy, rename (filename - date)
        I have got so far and the files move successfully but the rename doesnt seem to work - i dont get any error messages back though.

        The rename above would have  produced duplicate names ( the system would not allow.)

        The following uses the original name as part of the following new name.
        ( now the name is too long. ).  Play with it to reduce name size. Good luck. )


        for /f "delims=" %%a in (arc.txt) do (ren "c:\batch\archive\%%a" "%%a %dd%%mm%%yy%.txt" )

        C:\batch>kizzie.bat
        c:\batch\backup\liz1212.txt
        c:\batch\backup\liz1213.txt
                2 file(s) copied.
        Date = Sun 12/13/2009
        mm =12
        dd =Su
        yy =2009
         Volume in drive C has no label.
         Volume Serial Number is F4A3-D6B3

         Directory of c:\batch\archive

        12/13/2009  06:01 PM    <DIR>          .
        12/13/2009  06:01 PM    <DIR>          ..
        12/13/2009  12:25 PM                13 liz1212.txt
        12/13/2009  12:25 PM                13 liz1213.txt
        12/13/2009  12:25 PM                13 Su12 2009.txt
                       3 File(s)             39 bytes
                       2 Dir(s)  305,543,217,152 bytes free
         Volume in drive C has no label.
         Volume Serial Number is F4A3-D6B3

         Directory of c:\batch\archive

        12/13/2009  09:03 PM    <DIR>          .
        12/13/2009  09:03 PM    <DIR>          ..
        12/13/2009  12:25 PM                13 liz1212.txt Su12 2009.txt
        12/13/2009  12:25 PM                13 liz1213.txt Su12 2009.txt
        12/13/2009  12:25 PM                13 Su12 2009.txt Su12 2009.txt
                       3 File(s)             39 bytes
                       2 Dir(s)  305,543,213,056 bytes free
        C:\batch>

        p.s.  A full path to the name ( for ren ) of the original file works best. The file with the new name must remain in the same folder. copy or xcopy are more versatile.
        « Last Edit: December 13, 2009, 08:23:09 PM by billrich »

        Kizzie

          Topic Starter


          Newbie

          Re: getting stuck with rename scripts
          « Reply #4 on: December 14, 2009, 02:04:10 PM »
          Thankyou this second one worked great  ;D