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

Author Topic: how can i rename my current folder?  (Read 17568 times)

0 Members and 1 Guest are viewing this topic.

mioo_sara

    Topic Starter


    Intermediate

    how can i rename my current folder?
    « on: March 01, 2014, 07:15:11 AM »
    hi to all
    i want to rename my current folder (folder that i am in it) is it possible?
    with this script i can find my folder name but i cant rename it

    Quote
    for %%* in (.) do @echo %%~n*
    pause
    ren "%%~n*" "new"

    whats wrong?

    if its possible i want to remove any www.*.com from current folder name and replace it with space

    1- find current folder's name
    2-if there is any www. ???* .com in its name rename it(replace www. ???* .com )with space

    patio

    • Moderator


    • Genius
    • Maud' Dib
    • Thanked: 1769
      • Yes
    • Experience: Beginner
    • OS: Windows 7
    Re: how can i rename my current folder?
    « Reply #1 on: March 01, 2014, 07:53:51 AM »
    I don't think it can be done if the folder is in use,....
    " Anyone who goes to a psychiatrist should have his head examined. "

    foxidrive



      Specialist
    • Thanked: 268
    • Experience: Experienced
    • OS: Windows 8
    Re: how can i rename my current folder?
    « Reply #2 on: March 01, 2014, 08:53:18 AM »
    patio is right.

    You have to cd out of the folder, rename it and cd back in.  This assumes that no tasks are open in the folder or tree, too.

    mioo_sara

      Topic Starter


      Intermediate

      Re: how can i rename my current folder?
      « Reply #3 on: March 01, 2014, 09:46:38 AM »
      Quote
      patio is right.

      You have to cd out of the folder, rename it and cd back in.  This assumes that no tasks are open in the folder or tree, too.

      ok  guess we stepped back one  level  now how  could  it  be  done?
      i  want  program to  do  this
      1- find  current folder's name
      2-  if  there is  www.??*.com  in  current folder's  name
      so step one  level  back and
      3- rename it(remove www.??*.com and  replace it  with space)
      4- create a text file  named password  and  write www.??*.com in it
      how should  i do  it?




      « Last Edit: March 01, 2014, 10:16:36 AM by mioo_sara »

      foxidrive



        Specialist
      • Thanked: 268
      • Experience: Experienced
      • OS: Windows 8
      Re: how can i rename my current folder?
      « Reply #4 on: March 01, 2014, 10:27:56 AM »
      Show us some examples of the actual folder name.

      The easiest method to use depends on the format of the folder name.

      Salmon Trout

      • Guest
      Re: how can i rename my current folder?
      « Reply #5 on: March 01, 2014, 12:20:53 PM »
      C:\Users\Me\testme>for /f "delims=" %N in ("%cd%") do cd.. & ren "%~dpnN" "newname" && cd "newname"

      C:\Users\Me\testme>cd..   & ren "C:\Users\Mike\testme" "newname"   && cd "newname"

      C:\Users\Me\newname>


      mioo_sara

        Topic Starter


        Intermediate

        Re: how can i rename my current folder?
        « Reply #6 on: March 01, 2014, 12:31:38 PM »
        Quote
        Show us some examples of the actual folder name.

        The easiest method to use depends on the format of the folder name.

        dear foxidrive
         i have  lots  of  folders most  of  them  containing  files (compressed password protested)
         folders have website's names  on  themselves
        example
        win_media.player.12(www.dowloadfree.com)include.patch
        format.factory(www.getfree.net)freeware


        1-i want websites name( in  folder names) removed and replaced  with  empty  space
        2- put website name  in  a file(password.text) and  save  it in that folder
        3- if  i am  in  the  current  folder  with  website's  name  you  know  what  to  do 
        i think  we should  step back  one  level  and  do  above  instructions
        these scripts  will  be  used  in  a third party  program  later
        thanks

        « Last Edit: March 01, 2014, 12:41:57 PM by mioo_sara »

        mioo_sara

          Topic Starter


          Intermediate

          Re: how can i rename my current folder?
          « Reply #7 on: March 01, 2014, 12:37:38 PM »
          dear Salmon Trout
          it didn't  worked just  created a for  and cd file  in  my  current  folder
          please read  my  last  2  post  above
          thanks

          Salmon Trout

          • Guest
          Re: how can i rename my current folder?
          « Reply #8 on: March 01, 2014, 01:16:22 PM »
          4- create a text file  named password  and  write www.??*.com in it

          This sounds interesting. What is it for?

          mioo_sara

            Topic Starter


            Intermediate

            Re: how can i rename my current folder?
            « Reply #9 on: March 01, 2014, 01:29:46 PM »
            passwords.text  will  be  a file  that  later  will  be  used  by  a third  party  program 
            theses batches  too :)
            now please  write for  8) me a batch

            patio

            • Moderator


            • Genius
            • Maud' Dib
            • Thanked: 1769
              • Yes
            • Experience: Beginner
            • OS: Windows 7
            Re: how can i rename my current folder?
            « Reply #10 on: March 01, 2014, 02:06:35 PM »
            Heeee...this should be good.
            " Anyone who goes to a psychiatrist should have his head examined. "

            Geek-9pm


              Mastermind
            • Geek After Dark
            • Thanked: 1026
              • Gekk9pm bnlog
            • Certifications: List
            • Computer: Specs
            • Experience: Expert
            • OS: Windows 10
            Re: how can i rename my current folder?
            « Reply #11 on: March 01, 2014, 02:48:52 PM »
            He lost me from the start.
            Windows assigns folders for each user.
            To rename the folder that has the user's name is a security and logical problem.
            {begin sarcasm}
            Imagine three user on a computer, Alice, Bib can  Carl.
            Alice wants to change her name to Carl, but still have her folder named Alice.
            So Carl must change his name, put still have his folder.
            Unable to resolve this they ask Bob.
            Bob does not want to help!

            What is the scrip that can handle that?

            {end sarcasm}

            Salmon Trout

            • Guest
            Re: how can i rename my current folder?
            « Reply #12 on: March 01, 2014, 04:51:03 PM »
            win_media.player.12(www.dowloadfree.com)include.patch
            format.factory(www.getfree.net)freeware


            .... and you thought we wouldn't check those sites out?

            Quote
            1-i want websites name( in  folder names) removed and replaced  with  empty  space

            I expect you do.

            Quote
            2- put website name  in  a file(password.text) and  save  it in that folder

            *censored*, we're just a bunch of stupid coders who don't care... we'll help you with passwords, freeware, (passworded freeware????) odd looking sites? Great!

            Quote
            i think  we should  step back  one  level

            Well, I'm stepping back several levels.

            Quote
            these scripts  will  be  used  in  a third party  program  later

            I have no doubt they will.



            BC_Programmer


              Mastermind
            • Typing is no substitute for thinking.
            • Thanked: 1140
              • Yes
              • Yes
              • BC-Programming.com
            • Certifications: List
            • Computer: Specs
            • Experience: Beginner
            • OS: Windows 11
            Re: how can i rename my current folder?
            « Reply #13 on: March 01, 2014, 05:53:09 PM »
            Quote
            compressed password protested
            methinks the password doth protest too much.
            I was trying to dereference Null Pointers before it was cool.

            foxidrive



              Specialist
            • Thanked: 268
            • Experience: Experienced
            • OS: Windows 8
            Re: how can i rename my current folder?
            « Reply #14 on: March 01, 2014, 10:31:10 PM »
            win_media.player.12(www.dowloadfree.com)include.patch
            format.factory(www.getfree.net)freeware


            1-i want websites name( in  folder names) removed and replaced  with  empty  space

            How many spaces do you want left between the ( )?

            There could be issues with making a robust solution because the name format can be variable.  You could have names like this:

            win_media.player(type 2).12(www.dowloadfree.com)include.patch
            format.factory(www.getfree.net)freeware(supports Win2K)

            and the only way for a script to know which set of parentheses to work with is that in these two examples there is a www. after the opening (
            but it is possible that the website will not have a www. at the beginning of the URL.


            mioo_sara

              Topic Starter


              Intermediate

              Re: how can i rename my current folder?
              « Reply #15 on: March 01, 2014, 11:04:04 PM »
              thanks dear foxidrive
              i think  you're the  only  one  that  cares about question itself  but  others are all gouging :P

              well  folders  are with  passwords in  their  names  and  i  want  just  1- store  those  passwords  in  a file (password.text) in  their folder  and  then  remove password (and replace  with  1 space)
              so  final  folder's name  should  be  something  like  example  below
              example
              Quote
              best answers(www.my-website.com)all members
              should rename  to
              best answers all members
              ==========================
              my_broadcasting_www.mediafree.net
              should rename  to
              my_broadcasting

              foxidrive



                Specialist
              • Thanked: 268
              • Experience: Experienced
              • OS: Windows 8
              Re: how can i rename my current folder?
              « Reply #16 on: March 01, 2014, 11:27:00 PM »
              best answers(www.my-website.com)all members
              should rename  to
              best answers all members
              ==========================
              my_broadcasting_www.mediafree.net
              should rename  to
              my_broadcasting

              This makes the job more difficult as there is no well defined format for the password.

              mioo_sara

                Topic Starter


                Intermediate

                Re: how can i rename my current folder?
                « Reply #17 on: March 02, 2014, 12:01:42 AM »
                Quote
                This makes the job more difficult as there is no well defined format for the password.
                i know at this particular time  i  don't  need  passwords i  just  want  to  remove them  from  folder's name

                i  tried script  below  it's working  and  removed www.*.com from  folder's name  but  i  should type  www.*.com for  every folder
                i want program  detect  it  automatically

                Quote
                for /f "tokens=* delims= " %%i in ('dir /b "*.*"') do Set LIST=%%i& set LIST | ren "%%~fi" "%%LIST:www.my-website.com= %%"

                by the way  i tested it  on a file  and  not a folder

                but  this one works on  folders very good  but  i  want www.?.com or www.?.net detect automatically  and replaced with  space

                E
                Quote
                ECHO OFF
                SETLOCAL ENABLEDELAYEDEXPANSION
                FOR /D /R %%i IN (*.*) DO (
                SET "n=%%~nxi"
                SET n=!n:www.myp30.com= !
                ::SET n=!n:www.myp30.net= !
                    IF NOT "!n!" == "%%~nxi" MOVE "%%~i" "%%~dpi!n!"
                )
                « Last Edit: March 02, 2014, 12:17:54 AM by mioo_sara »

                foxidrive



                  Specialist
                • Thanked: 268
                • Experience: Experienced
                • OS: Windows 8
                Re: how can i rename my current folder?
                « Reply #18 on: March 02, 2014, 09:17:40 AM »
                The task does not have a well defined format so a general script is impossible and so it has to have an exception for every type of format that is used.

                This batch file works for the two formats you have shown, and will handle www.*.com and www.*.net, and it uses the repl.bat tool by Dave Benham.

                It creates the password.txt file inside the folder with the website address
                - and the batch file has to be launched from the path and not located inside the folder, because doing that would lock the folder itself and the rename would fail.

                If you can deal with this folder "best answers(www.my-website.com)all members"
                becoming this "best answers()all members"
                and this folder "my_broadcasting_www.mediafree.net"
                becoming this "my_broadcasting_"
                so that only the website address is removed then it could be simplified and would handle other folder-name formats.

                V2.0

                Code: [Select]
                @echo off
                for %%a in ("%cd%") do set "folder=%%~nxa"
                cd..
                del renfolder.bat 2>nul
                :: handles (www.aaa.com)
                echo "%folder%"|repl ".(.*)\((www\..*?\.com)\)(.*)." ">$&\password.txt echo $2& ren $& \q$1 $3\q" axi  >>renfolder.bat
                :: handles (www.aaa.net)
                echo "%folder%"|repl ".(.*)\((www\..*?\.net)\)(.*)." ">$&\password.txt echo $2&ren $& \q$1 $3\q" axi  >>renfolder.bat
                :: handles _www.aaa.com
                echo "%folder%"|repl ".(.*)_(www\..*?\.com)(.*)." ">$&\password.txt echo $2&ren $& \q$1 $3\q" axi    >>renfolder.bat
                :: handles _www.aaa.net
                echo "%folder%"|repl ".(.*)_(www\..*?\.net)(.*)." ">$&\password.txt echo $2&ren $& \q$1 $3\q" axi    >>renfolder.bat
                call renfolder.bat
                del renfolder.bat 2>nul
                pause

                This uses a helper batch file called `repl.bat` - download from:  https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat

                Place `repl.bat` in the same folder as the batch file or in a folder that is on the path.
                « Last Edit: March 02, 2014, 09:32:10 AM by foxidrive »

                mioo_sara

                  Topic Starter


                  Intermediate

                  Re: how can i rename my current folder?
                  « Reply #19 on: March 02, 2014, 01:16:24 PM »
                  well dear foxidrive i tested your script but  i wonder  if  it  was my  problem :P  or the  script  but it didn't worked!
                  here's what  i  did  for  testing  the script
                  1-i  made a new folder  named it test folder
                  2- inside  it  i made  another 2 folders with  website name  in  their names
                  examle
                  my-testing1_www.myweb.com_in test
                  my-testing2_www.mysite.net

                  3- now i  copied both (repl.bat and test-batch.bat) in test folder (next to those folders)
                  now  i  tried  the script test-batch.bat but  nothing  happened

                  what  do you  think? ???
                  « Last Edit: March 02, 2014, 01:50:51 PM by mioo_sara »

                  foxidrive



                    Specialist
                  • Thanked: 268
                  • Experience: Experienced
                  • OS: Windows 8
                  Re: how can i rename my current folder?
                  « Reply #20 on: March 02, 2014, 03:47:16 PM »
                  3- now i  copied both (repl.bat and test-batch.bat) in test folder (next to those folders)
                  now  i  tried  the script test-batch.bat but  nothing  happened

                  Perhaps I wasn't clear enough but I said this:

                  Quote
                  - and the batch file has to be launched from the path and not located inside the folder, because doing that would lock the folder itself and the rename would fail.

                  You must put the batch file and repl.bat in a folder on the path, such as c:\windows or c:\windows\system32

                  When you are at a cmd prompt inside the folder, then you type the batch-command

                  mioo_sara

                    Topic Starter


                    Intermediate

                    Re: how can i rename my current folder?
                    « Reply #21 on: March 03, 2014, 01:36:41 AM »
                    dear foxidrive
                    i tested your v2 script and  i  don't  know  why  it's still not responding correctly ???
                    here's result  of  my  test
                    =====================================================
                    1-first  of all  i have  windows xp sp3 installed  on  my  pc  and  my win-xp  is  in  drive  f:
                    (i  don't think  if  it  would  be  the reason of that)
                    2- in first try i copied both  files(repl.bat and test-batch.bat) to f:\windows
                    then i clicked on f:\mytest\go.bat
                    (inside of go.bat there is  this comment f:\windows\test-batch.bat )
                    nothing but a black screen that has vanished!
                    inside folder ( f:\mytest\ ) there are some folders that their names have website's name
                    i checked them  but nothing has been changed! no rename and  no  password.txt
                    3- so  in another test i copied both (repl.bat and test-batch.bat) to f:\windows\system32
                    but still nothing happened
                    4- in  another test i tried CMD i opened CMD and typed f:\mytest\go.bat
                    still no successful result ::)
                    =============================
                    now i have some questions
                    should i  really  do this process with  copying some files  in  windows?
                    i mean  to me it doesn't seem  to  be that  difficult  for a task like this
                    i think  program  can  do  some Dir find folders that their names has letters begin with (www.) and end with .com or .net and remove these letters from begin to  end right?
                    and create a password.text in folder containing (www.....com)

                    foxidrive



                      Specialist
                    • Thanked: 268
                    • Experience: Experienced
                    • OS: Windows 8
                    Re: how can i rename my current folder?
                    « Reply #22 on: March 03, 2014, 02:47:03 AM »
                    You said that you wanted to do this from inside the folder.  You can't click on a batch file inside the folder though because it will lock the folder and it cannot be renamed.

                    Just to prove it works, place the two batch files repl.bat and test-batch.bat into c:\windows and then open a cmd prompt inside the folder to be renamed.

                    Then type test-batch and you should see the folder renamed and a password.txt appear inside the folder.


                    mioo_sara

                      Topic Starter


                      Intermediate

                      Re: how can i rename my current folder?
                      « Reply #23 on: March 03, 2014, 11:36:13 AM »
                      wow ! dear foxidrive
                      it actually  worked !! i can't even  believe it ! ;D ;D ;D :D :D :D :D
                      you  know  if  you  read my  first post  in  this topic i was looking for  a way  to  rename  my  current  folder  but  cuz  it was being  used  by the  explorer  and  even  batch itself  some guys  in  the  forum  said  it's  not  possible  .  and  i was  disappointed so  i changed  my  idea and tried another  way(i  decided  to  rename  another folders  and  not  current  folder)
                      but  now  you proved  that  it's  possible 
                      thank  you  very  very  very  much  ;) ;) ;) ;) you  solved  one  of  my  biggest  problems cuz there  where hundreds  of  folders that  i wanted  to  be renamed  but  cuz my  program  was  added  to  my  right  click  menu  i  wanted  just  selected  folder  renamed and  not  all  of  them(that's  my  current  folder story)
                      and  sorry  for  the  late  answer  i was  out  of  town  for  a few  hours
                      thanks  again  i  hope  you  have  very  good  year  ahead  for  yourself  and  for  your family

                      mioo_sara

                        Topic Starter


                        Intermediate

                        Re: how can i rename my current folder?
                        « Reply #24 on: March 03, 2014, 12:22:07 PM »
                        sorry to  disturb  you  again  dear  foxidrive  i  don't know  why  program  is  not  stable  i  mean  i  tried  it  with  lots  of  other folders  and  although  their  structures  where  not  different  in  names but  program  didn't  worked  anymore  and  i  even  tried  to  make  a  folder  with my  first  test  structure (first  successful  test)  but  it  failed  again  and  nothing  happened
                        i even  disabled  my  kaspersky  antivirus but  nothing changed
                        don't  you  think  if  it  would  be  better  to  do  it  with  DIR and  if  program  found  folder  with  website  names  ask  if  i want it  to  be  renamed  (yes/no)
                        i think  copying  .bat  file  in  windows  make  it  more unstable  than  before  i  can  remove  program  from  my  right  click  menu (forget about current folder)and  work  with search and replace  (yes/no)
                        what do  you  think?

                        mioo_sara

                          Topic Starter


                          Intermediate

                          Re: how can i rename my current folder?
                          « Reply #25 on: March 03, 2014, 12:37:49 PM »
                           ;D ;D ;D ;D
                          now  i'v found  reason of  the  problem
                          problem  was  because of folder's name and( ) those  that their names  was in () just has been  renamed
                          ok ! ok i  can solve  this  problem  dear  foxidrive  thanks  again
                           :) :) :) :) :) :) :) :)