1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Batch file to copy a file from folder and rename it in another folder

Discussion in 'Software Development' started by far001han, Feb 13, 2013.

Thread Status:
Not open for further replies.
Advertisement
  1. far001han

    far001han Thread Starter

    Joined:
    Feb 13, 2013
    Messages:
    7
    Hello all , i am new to batch programming.

    I wish to have a batch file to read .apk file from folder and then copy it to another folder. Then it should rename the copied apk file to test.apk

    eg:
    i have a file in folder e:\apps\angrybirds.apk , I want to copy this angrybirds.apk to d:\apps and rename it to test.apk

    Here the file names in the e:\apps\ will be changing. So what ever may be the name , it should read the name of the file from e:\apps\ folder , copy it to d:\apps\ and rename it to "test.apk" . Test.apk is a fixed rename
     
  2. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,786
    Down and dirty as long as there are no other APK files in the source directory.

    Code:
    copy e:\apps\*.apk d:\apps\test.apk
     
  3. far001han

    far001han Thread Starter

    Joined:
    Feb 13, 2013
    Messages:
    7
    Hii , I tried it , its creating test.apk , but the file content is totally differnet . the content of *.apk is not same as test.apk
     
  4. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,786
    sorry forgot the /B switch.

    copy /B e:\apps\*.apk d:\apps\test.apk
     
  5. far001han

    far001han Thread Starter

    Joined:
    Feb 13, 2013
    Messages:
    7
    Thanks Squashman.. Awesome its working :)
     
  6. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,786
    I work with text files all the time so I am used to just doing it that way. I occasionally have to use the Binary switch for certain things I do.
     
  7. far001han

    far001han Thread Starter

    Joined:
    Feb 13, 2013
    Messages:
    7
    If i have more than one apk file, then how should i handle this??
     
  8. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,786
    Well then obviously you would need more than one output in your destination folder. How do you want to name the files in the destination folder?
     
  9. far001han

    far001han Thread Starter

    Joined:
    Feb 13, 2013
    Messages:
    7
    the output names should be test1.apk , test2.apk ,...... and soo on
     
  10. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,786
    Code:
    @echo off
    setlocal enabledelayedexpansion
    
    pushd E:\apps
    
    set count=0
    FOR %%G in (*.apk) do (
    	set /a count+=1
    	copy "%%~G" D:\apps\test!count!.apk
    )
    popd
     
  11. far001han

    far001han Thread Starter

    Joined:
    Feb 13, 2013
    Messages:
    7
    Thanks Squashman.. its working fine
     
  12. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1089334

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice