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

Author Topic: Rename/replace  (Read 36910 times)

0 Members and 1 Guest are viewing this topic.

Salmon Trout

  • Guest
Re: Rename/replace
« Reply #75 on: January 10, 2010, 08:37:01 AM »
Just throwing this out there: isn't the /s switch supposed to come after the /b switch?

The switches and filespecs for dir can come in any order

dir /b /s *.txt
dir /s /b *.txt
dir *.txt /s /b
dir *.txt /b /s
dir /b *.txt /s
dir /s *.txt /b

are all equivalent
« Last Edit: January 10, 2010, 09:06:08 AM by Salmon Trout »

Helpmeh



    Guru

  • Roar.
  • Thanked: 123
    • Yes
    • Yes
  • Computer: Specs
  • Experience: Familiar
  • OS: Windows 8
Re: Rename/replace
« Reply #76 on: January 10, 2010, 08:48:36 AM »
Oookkk. I wasn't sure, as I've always used /b /s and have never encountered problems (except when there are way too many files/folders in one folder).
Where's MagicSpeed?
Quote from: 'matt'
He's playing a game called IRL. Great graphics, *censored* gameplay.

Salmon Trout

  • Guest
Re: Rename/replace
« Reply #77 on: January 10, 2010, 08:56:54 AM »
Oookkk. I wasn't sure, as I've always used /b /s and have never encountered problems (except when there are way too many files/folders in one folder).

Check them out. I just did.

Helpmeh



    Guru

  • Roar.
  • Thanked: 123
    • Yes
    • Yes
  • Computer: Specs
  • Experience: Familiar
  • OS: Windows 8
Re: Rename/replace
« Reply #78 on: January 10, 2010, 09:02:53 AM »
Check them out. I just did.

No I believe you. I believed you when you posted it. Anyway, I can't test the now. iPod Touch, remember?
Where's MagicSpeed?
Quote from: 'matt'
He's playing a game called IRL. Great graphics, *censored* gameplay.

myshutterclicks



    Rookie

    Re: Rename/replace
    « Reply #79 on: January 10, 2010, 02:18:12 PM »
    Here is the code with the /s that you suggested and it does not work for some reason.

    @echo off
    setlocal enabledelayedexpansion
    for /f "delims=" %%a in ('dir /s /b *.myname.*') do (
    set fileorig=%%a
    set filenew=!fileorig:.myname=!
    rename !fileorig! !filenew!
    )

    Without the /s it works for the directory where I run it from. I can double click or run from command line, the result is the same.  Also a point to note is that I do not have double quote in the rename command and it works just fine.

    I never did any windows/dos shell programming but have basic knowledge of programming.


    Thanks,
    myshutterclicks.


    Please post the code you used.  We can modify from there.

    The code offered was one line from #1 post in this thread.  All of the batch file must be used:

    Code: [Select]
    @echo off
    setlocal enabledelayedexpansion
    rem for /f "delims=" %%a in ('dir /b') do (
    for /f "delims=" %%a in ('dir /s /b') do (
    set fileorig=%%a
    set filenew=!fileorig:_= !
    ren !fileorig! "!filenew!"
    )

    "Save it in the folder which contains the files you want to change. "

    Save the above code to a file with .bat extention.  For example:  namepic.bat.  Then type namepic.bat at the command line and press  return.


    C:\>namepic.bat

    myshutterclicks



      Rookie

      Re: Rename/replace
      « Reply #80 on: January 10, 2010, 02:43:32 PM »
      Since the basic code works for a directory I think the following idea might work. but I don't have the knowledge base to do the programming in shell.

      1. Parameterize the basic code, ie. pass the directory path to this script.
      2. Make another script to scan through the subdirectories recursively and when a it finds a directory call the first batch file (from point #1) with the directory as parameter.

      This code seems to rename files recursively. May be the gurus can tweak it to make it work with the above routine.

      For /r %%x in (*.jpg) do  ren "%%x" *.jpeg

      Notice the /r switch in the FOR clause for scanning the directories recursively.


      Thanks,
      myshutterclicks

      « Last Edit: January 10, 2010, 03:09:20 PM by myshutterclicks »

      BillRichardson



        Intermediate

        Thanked: 15
        Re: Rename/replace
        « Reply #81 on: January 10, 2010, 03:54:43 PM »
        For /r %%x in (*.jpg) do  ren "%%x" *.jpeg
        Notice the /r switch in the FOR clause for scanning the directories recursively.

        We have pasted my level of expertise.   

        Contact Salmon Trout directly.

        The two of you  can make the this work. 

        Size and volume of the image files might be part of the problem.

        Good luck

        bye
        Bill Richardson

        myshutterclicks



          Rookie

          Re: Rename/replace
          « Reply #82 on: January 10, 2010, 03:58:26 PM »
          Hi Bill,

          Thanks for your time and thoughts for exploring the dir command with /s option. Hopefully someone will be able to come up with the solution.


          Thanks,
          myshutterclicks



          We have pasted my level of expertise.   

          Contact Salmon Trout directly.

          The two of you  can make the this work. 

          Size and volume of the image files might be part of the problem.

          Good luck

          bye

          Helpmeh



            Guru

          • Roar.
          • Thanked: 123
            • Yes
            • Yes
          • Computer: Specs
          • Experience: Familiar
          • OS: Windows 8
          Re: Rename/replace
          « Reply #83 on: January 10, 2010, 07:18:23 PM »
          Size and volume of the image files might be part of the problem.
          The DIR command can be very finicky with huge amounts of files/folders in one root.

          Does the DIR command stop mid-process and exit (not giving an error message), freeze (also not giving an error message), or just give an error message and not do anything?

          The only time I've actually messed up the DIR command (when I typed it in properly) was when there were tens of thousands of folders, within one sub folder (I was trying to see the network drive), although the problem could probably be reproduced with a much less amount.
          Where's MagicSpeed?
          Quote from: 'matt'
          He's playing a game called IRL. Great graphics, *censored* gameplay.

          Geek-9pm


            Mastermind
          • Geek After Dark
          • Thanked: 1026
            • Gekk9pm bnlog
          • Certifications: List
          • Computer: Specs
          • Experience: Expert
          • OS: Windows 10
          Re: Rename/replace
          « Reply #84 on: January 10, 2010, 07:44:15 PM »
          Quote
          Does the DIR command stop mid-process and exit (not giving an error message), freeze (also not giving an error message), or just give an error message and not do anything?
          Good question. There was, at one time, some kind of limit in NT as to how much stuff you can make the command interpreter do in one big gulp.
          EDIT: found this
          Quote
          There are more files in the directory than the command interpreter (COMMAND.COM) can sort. The maximum amount of memory that COMMAND.COM can allocate for a DIR operation is 64 kilobytes minus 512 bytes. Each file displayed by the DIR command requires 22 bytes for its entry, making the total number of files that can be displayed in a sorted directory equal to 2295 files [(65536-512)/22].
          # Microsoft MS-DOS 6.22 Standard Edition
          # Microsoft Windows 95
          http://support.microsoft.com/kb/100842
          « Last Edit: January 10, 2010, 07:54:20 PM by Geek-9pm »

          Helpmeh



            Guru

          • Roar.
          • Thanked: 123
            • Yes
            • Yes
          • Computer: Specs
          • Experience: Familiar
          • OS: Windows 8
          Re: Rename/replace
          « Reply #85 on: January 10, 2010, 08:01:47 PM »
          Very good find...although this is what happened for me:

          It displayed a list of all folders in the root of the drive (about 300 in all), went down one level in the last folder, displayed the contents...eventually displaying over 1000 files/folders. It then encounters a folder I like to call the beast (the one with 20 000+ folders in it). It makes it through a decent way then just sits there. Although it definately goes through more than 1000 (over 2000 if including the ones from the directory levels above). 
          Where's MagicSpeed?
          Quote from: 'matt'
          He's playing a game called IRL. Great graphics, *censored* gameplay.

          myshutterclicks



            Rookie

            Re: Rename/replace
            « Reply #86 on: January 10, 2010, 08:04:58 PM »
            I am testing this with few files only. So no question of having huge number of files.

            I get this error with the /s option with just 3 files in one directory and it does not even rename the files under the same directory. It works file without the /s option. But then that's not for recursive.

            The syntax of the command is incorrect.
            The syntax of the command is incorrect.
            The syntax of the command is incorrect.

            Thanks,
            myshutterclicks





            The DIR command can be very finicky with huge amounts of files/folders in one root.

            Does the DIR command stop mid-process and exit (not giving an error message), freeze (also not giving an error message), or just give an error message and not do anything?

            The only time I've actually messed up the DIR command (when I typed it in properly) was when there were tens of thousands of folders, within one sub folder (I was trying to see the network drive), although the problem could probably be reproduced with a much less amount.

            Helpmeh



              Guru

            • Roar.
            • Thanked: 123
              • Yes
              • Yes
            • Computer: Specs
            • Experience: Familiar
            • OS: Windows 8
            Re: Rename/replace
            « Reply #87 on: January 10, 2010, 08:08:09 PM »
            I am testing this with few files only. So no question of having huge number of files.

            I get this error with the /s option with just 3 files in one directory and it does not even rename the files under the same directory. It works file without the /s option. But then that's not for recursive.

            The syntax of the command is incorrect.
            The syntax of the command is incorrect.
            The syntax of the command is incorrect.

            Thanks,
            myshutterclicks





            Can you post all code in your script right now? A syntax error means the switches/etc. were not written properly.
            Where's MagicSpeed?
            Quote from: 'matt'
            He's playing a game called IRL. Great graphics, *censored* gameplay.

            myshutterclicks



              Rookie

              Re: Rename/replace
              « Reply #88 on: January 10, 2010, 08:17:58 PM »
              Can you post all code in your script right now? A syntax error means the switches/etc. were not written properly.

              Here is the code:

              ---------------------------------------------
              @echo off
              setlocal enabledelayedexpansion
              for /f "delims=" %%a in ('dir /s /b *_MG_*.JPG') do (
              set fileorig=%%a
              set filenew=!fileorig:_MG_=!
              rename !fileorig! "!filenew!"
              )


              pause
              ---------------------------------------

              I have these files in the directory.


              _MG_3338.JPG
              _MG_3339.JPG
              _MG_3340.JPG
              _MG_3341.JPG

              ------------------------------------------

              Here is the error message:

              The syntax of the command is incorrect.
              The syntax of the command is incorrect.
              The syntax of the command is incorrect.
              The syntax of the command is incorrect.
              Press any key to continue . . .


              ---------------------------------------------------


              The code works just fine without the /s.

              Thanks,
              myshutterclicks

              Geek-9pm


                Mastermind
              • Geek After Dark
              • Thanked: 1026
                • Gekk9pm bnlog
              • Certifications: List
              • Computer: Specs
              • Experience: Expert
              • OS: Windows 10
              Re: Rename/replace
              « Reply #89 on: January 10, 2010, 08:49:37 PM »
              Doing  DIR /? gives the list of options.
              It states you give the file name first and follow with the switches.
              So why not try it the recommended way?
              Using a feature that is not given in the documentation is not wise, unless you have a reason for it.
               (So you just want to see what happens?)