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

Author Topic: copy and rename file with path name  (Read 15228 times)

0 Members and 1 Guest are viewing this topic.

novice84

    Topic Starter


    Rookie

    • Experience: Beginner
    • OS: Windows 7
    Re: copy and rename file with path name
    « Reply #15 on: June 28, 2013, 08:40:07 AM »
    THANKS FOR REPLY
    1. SO TOP LINE NO NEED TO EDIT, IT'S A REMARK
    2. I GAVE FILE NAME P.BAT AND AS TOP LINE JUST FOR REMARK, SO DOESN'T MATTER IF CORRECT NAME AND TYPE LOCATIONS.
    3. I PLACED P.BAT IN C:\TEST AND OPEN CMD THERE, TRIED TYPING COMMAND IN CMD AS SHOWN BELOW :
    C:\TEST> P.BAT E:\FOLDER\NAME C:\TEST TXT
    NOTHING HAPPENED  :( :( :( :(

    Lemonilla



      Apprentice

    • "Too sweet"
    • Thanked: 70
    • Computer: Specs
    • Experience: Experienced
    • OS: Windows 7
    Re: copy and rename file with path name
    « Reply #16 on: June 28, 2013, 12:46:15 PM »
    try adding quotes
    Code: [Select]
    p.bat "e:\folder\name" "c:\test" txt
    Quote from: patio
    God Bless the DOS Helpers...
    Quote
    If it compiles, send the files.

    novice84

      Topic Starter


      Rookie

      • Experience: Beginner
      • OS: Windows 7
      Re: copy and rename file with path name
      « Reply #17 on: June 28, 2013, 06:21:45 PM »
      Also Tried that but doesn't work
      there is something wrong with path specification and ext specification
      I think I can't specify it correct way

      Lemonilla



        Apprentice

      • "Too sweet"
      • Thanked: 70
      • Computer: Specs
      • Experience: Experienced
      • OS: Windows 7
      Re: copy and rename file with path name
      « Reply #18 on: June 28, 2013, 07:31:58 PM »
      Try adding "::" before '@echo off ' (just like in line 1)
      This should be the 3rd line.

      then:
      Code: [Select]
      p.bat "e:\folder\name" "c:\test" txt 1>p_bat_Test_Log.txt 2>&1
      and post p_bat_Test_Log.txt

      This will allow us to look at what is running and what is not.
      Quote from: patio
      God Bless the DOS Helpers...
      Quote
      If it compiles, send the files.

      novice84

        Topic Starter


        Rookie

        • Experience: Beginner
        • OS: Windows 7
        Re: copy and rename file with path name
        « Reply #19 on: June 28, 2013, 08:38:10 PM »
        attached 3 files generated in C:test folder and batch file was also in same folder


        [recovering disk space, attachment deleted by admin]

        Lemonilla



          Apprentice

        • "Too sweet"
        • Thanked: 70
        • Computer: Specs
        • Experience: Experienced
        • OS: Windows 7
        Re: copy and rename file with path name
        « Reply #20 on: June 28, 2013, 09:01:51 PM »
        try changing 'copy' to 'xcopy'? I have never tried to move things between drives with batch.  It seems to be copying the logs.
        Quote from: patio
        God Bless the DOS Helpers...
        Quote
        If it compiles, send the files.

        novice84

          Topic Starter


          Rookie

          • Experience: Beginner
          • OS: Windows 7
          Re: copy and rename file with path name
          « Reply #21 on: June 28, 2013, 10:04:28 PM »
          nope still nothing working.
          it look like it is looking in same folder where batch file is located and the specified paths not picking up

          Squashman



            Specialist
          • Thanked: 134
          • Experience: Experienced
          • OS: Other
          Re: copy and rename file with path name
          « Reply #22 on: June 29, 2013, 12:51:57 AM »
          Read the help on the CD command. I normally dont use the option that is in there that you are missing. I normally use pushd.

          Salmon Trout

          • Guest
          Re: copy and rename file with path name
          « Reply #23 on: June 29, 2013, 02:17:51 AM »

          in code top line is :

          :: $renameWithPath.bat <source path> <destination path> <extentions>
          I am just changing top line of code like this :

          :: $renameWithPath.bat "E:\Checking\Routine\Afternoon\15-04-13" "C:\test" "*.txt"

          can you please tell me what am missing or making mistake ?

          A line starting with a colon is a label. A line starting with two colons is a broken label, sometimes used as a comment. (This is a bad practice, better to use REM). Comments are not executed, so you can change them all you like and it won't change what the batch script does.

          foxidrive



            Specialist
          • Thanked: 268
          • Experience: Experienced
          • OS: Windows 8
          Re: copy and rename file with path name
          « Reply #24 on: June 29, 2013, 02:43:43 AM »
          Rem lines are parsed by cmd - if you put < and | in a REM it will barf.

          When using :: it doesn't parse the commant at all, which is why it is a useful way to add comments.

          Salmon Trout

          • Guest
          Re: copy and rename file with path name
          « Reply #25 on: June 29, 2013, 03:15:12 AM »
          Rem lines are parsed by cmd - if you put < and | in a REM it will barf.

          When using :: it doesn't parse the commant at all, which is why it is a useful way to add comments.

          A good point, which I had overlooked. I suppose I don't like them because if a person gets in the habit of always using broken labels as comments, one day they will use it in a parenthetical block, which will also fail or barf.



          novice84

            Topic Starter


            Rookie

            • Experience: Beginner
            • OS: Windows 7
            Re: copy and rename file with path name
            « Reply #26 on: June 29, 2013, 03:34:10 AM »
            thanks Salmon Trout & foxidrive for explaining REM & ::
            @Squashman - I tried Pushd command also, but I think something need to be fixed in code.

            is there any way we can get this code working ?
            is it possible to copy files with path name in file name ?

            thanks in advance.

            foxidrive



              Specialist
            • Thanked: 268
            • Experience: Experienced
            • OS: Windows 8
            Re: copy and rename file with path name
            « Reply #27 on: June 29, 2013, 05:27:25 AM »
            This is meant to rename certain filetypes and include the path from the current folder.
            It writes RENFILE.BAT which will rename the files if you run it, so you can check it first.


            Code: [Select]
            @echo off
            echo.@echo off> renfile.bat
            for /f "delims=" %%a in ('dir *.jpg *.png *.gif /b /s /a-d ') do call :next "%%a"
            echo renfile.bat created
            pause
            goto :eof
            :next
            set "var=%~1"
            call set "var=%%var:%cd%=%%"
            set "var=%var:\=_%"
            >>renfile.bat echo ren "%~1" "%var:~1%"

            novice84

              Topic Starter


              Rookie

              • Experience: Beginner
              • OS: Windows 7
              Re: copy and rename file with path name
              « Reply #28 on: June 29, 2013, 05:52:07 AM »
              Hi Foxidrive
              In another thread I appreciate you help.
              but from this code it looks it is to rename files, but as mentioned I want to copy file to different location first and then rename those.
              Problem is I have folders with name as different dates and files names are same
              If you look at posts in this thread I have mentioned I have same file name in different folders. So I want to copy as well as rename them to different location with path in the name.
              Some folders have sub folders also, so code should be able to copy files from deep tree sub folders also.
              I was wondering if we can have user input of source and destination paths with SET variable like
              set /p source=
              and
              set /p Dest= 


              foxidrive



                Specialist
              • Thanked: 268
              • Experience: Experienced
              • OS: Windows 8
              Re: copy and rename file with path name
              « Reply #29 on: June 29, 2013, 05:56:12 AM »
              All you have to do is change this line

              Code: [Select]
              >>renfile.bat echo ren "%~1" "%var:~1%"
              to this:

              Code: [Select]
              >>renfile.bat echo copy "%~1" "d:\new\folder\%var:~1%"
              Then see if the copy commands look right before launching the renfile.bat batch file.  Make sure d:\new\folder exists first.