Bat Script Thingy


  1. Posts : 9
    Windows 7 Home Premium
       #1

    Bat Script Thingy


    Hi,

    I was wondering if someone could tell me how to do some commands (in order) so I can just plug in a Flash Drive with the bat file on it and double click on it. Double clicking on it would launch it and cause it to grab files off the computer it is plugged into (they're my files) and transfer them to the flash drive. I don't know what the drive letter of the flash drive is, as it is different between computers.

    So here is what I want it to do:

    1. Move all the files/folders in the folder to a zip file
    2. Take that zip file and move it to the flash drive. The drive letter won't be known.

    Please tell me how to do this so I can *quickly* get the files and move on.

    Thanks

    -Happyman7
      My Computer


  2. Posts : 1,506
    W7 Ult. x64 | OS X
       #2

    The command line utility to copy files and directory trees is:

    XCOPY [SOURCE] [DESTINATION]

    i.e.

    XCOPY C:\...\ParentFolderName D:\DestinationFolder

    This will copy all of the files and folders within the source folder to the destination folder.

    You can assign your flash drive to a specific drive letter through disk management. This will only help if you're doing this on the same computers over and over.

    Disk Management:
    Start > Search "computer management" > Enter > Click on Disk Management > Right Click Drive in Question > Assign Letters & Paths > Assign a specific letter.

    To compress the files you'll probably need a third party program like WinZip, PKZip or EasyZip with a command line function.

    For Winzip:http://www.winzip.com/prodpagecl.htm

    Command Line Utilities accessible via .BAT file:
    http://www.memecode.com/docs/winzip.html

    In other words your .BAT file might look something like this if you flash drive was locked to F:

    winzip32 -min -a -r -es F:\zipfilename.zip %USERPROFILE%\Downloads\Files\

    Note: -min = Minimized, -a = Add, -r = Include Subfolders, -es = Super Fast Compression

    If i've done that correctly, that should place all of the files located in C:\Users\yourusername\Downloads\Files\ in a zip file named zipfilename.zip located in drive F:

    To extract the files at a different computer with the flash drive locked to F:

    winzip32 -e -o F:\zipfilename.zip %USERPROFILE%\Downloads\DestinationFolder\

    Note: -e = Extract, -o = Overwrite

    That should move the files from the zip file on drive F: to a folder called DestinationFolder in C:\Users\yourusername\Downloads
      My Computer


  3. Posts : 9
    Windows 7 Home Premium
    Thread Starter
       #3

    I can't exactly get into any settings because it is a public/educational computer. So can't it find itself the Drive letter? Also, I want to try and avoid installing any applications. :P I forgot to mention that the computer the bat file runs on is running Windows XP. (It's the most stable for public use :P)
      My Computer


  4. Posts : 4
    Windows 7 Pro
       #4

    I cant exactly help with ziping as i dont know the commands for that. I have a batch file i use to copy a avi files from folders and copy them in to a new folder called newTV_2010-04-28.( i use the year month day as it sorts better when put in a list) I run the batch file from the removable drive which can have different letter each time but the source files are always in the same location.

    here is the code i use
    ---------------------
    MD newTV_%Date:~-4,4%-%Date:~-7,2%-%Date:~-10,2%
    cd \newTV_%Date:~-4,4%-%Date:~-7,2%-%Date:~-10,2%
    xcopy l:\1monday\*.avi
    xcopy l:\2tuesday\*.avi
    xcopy l:\3wednesday\*.avi
    xcopy l:\4thursday\*.avi
    xcopy l:\5friday\*.avi
    xcopy l:\6saturday\*.avi
    xcopy l:\7sunday\*.avi
    Pause
    -------------------------------

    MD newTV_%Date:~-4,4%-%Date:~-7,2%-%Date:~-10,2%
    this line creates a new folder called newTV with the current date added (date is in the format of year-mm-dd) change the newTV_ to name of your choice

    cd \newTV_%Date:~-4,4%-%Date:~-7,2%-%Date:~-10,2%
    this line moves program focus into the newly created folder

    xcopy l:\1monday\*.avi
    xcopy l:\2tuesday\*.avi
    xcopy l:\3wednesday\*.avi
    xcopy l:\4thursday\*.avi
    xcopy l:\5friday\*.avi
    xcopy l:\6saturday\*.avi
    xcopy l:\7sunday\*.avi
    these lines copy all avi files from the source locations, you could simply change that to xcopy "your files location\*.*" to copy allfiles from chosen location to the new directory.

    Pause
    i genrally like to leave a pause command in so that i can look over what has been done but if you leave it out it is not a problem

    i called the file weeklycopy.bat and it simply sits on the root of the storage device

    an example of code you could use would be

    -------------------------------------
    MD new_%Date:~-4,4%-%Date:~-7,2%-%Date:~-10,2%
    cd \new_%Date:~-4,4%-%Date:~-7,2%-%Date:~-10,2%
    xcopy l:\1monday /e
    pause
    ---------------------------------------

    what this code would do is create a new folder on your flash drive called new_2010-04-28
    and copy all the contents of the selected folder to the new folder.

    simply change l:1monday to the folder you want to copy and remember if the any part of the folder path has a space put " at each end eg you would use xcopy "c:\my stuff" /e instead of xcopy c:\my stuff /e as spaces will cause it fail unless " marks are used at each end.



    Hope this will help.
    Last edited by akathekrisc; 28 Apr 2010 at 10:25.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 16:45.
Find Us