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.

Need Batch File Help

Discussion in 'Software Development' started by Agolfnut, Jan 28, 2013.

Thread Status:
Not open for further replies.
  1. Agolfnut

    Agolfnut Thread Starter

    Jan 28, 2013
    I have never done batch files before and have no clue were to start so....

    I need a batch file that can do the following:
    Goto to a text file with names in the following format:

    Directory 002030 - AK Anchorage v16 - LMB
    Complete Heading: Adoption Agencies

    Directory 005012 - CA Airport Metro v30 - SPR
    Complete Heading: Adoption Services

    I want to copy the text that is in red to folder (different location) with the following names format (typical):


    I want to rename the above pdf file replacing the red portion of the name with the previous copied text to get a file name that is;

    AK Anchorage v16 - LMB.pdf

    I then want to go back to the next name in the text file and repeat the process.
    Can it be done?
  2. nikomaster


    Jan 15, 2013
    Just write a regulat text file and type all you need in MSDOS commands:

    @echo off
    copy sourcefile c:\path\destnamefile
    ren sourcefilename newfilename

    Save the file with extension .bat
  3. draceplace


    Jun 8, 2001
    Vbscripts can traverese folder structures and rename/copy/move base on logic that you can dream up. If your interested in doing vbscript? Nikomaster can probably advise to same in DOS.

    open text file paste and save as vbs. Change StartFolder and MoveTo folders to suit your needs.

    '-- Dan aka draceplace 01/30/2013---------------------------------------
    '---Run at your own risk-Vbscripts can tear stuff up!
    'don't move copy to the same folder
    ' objStartFolder - set this
    ' strMoveToFolder - set this
    ' ---------------------------------------------------------------
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Public cntFileID
    cntMove = 0
    cntFileID = 0
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    objStartFolder = "H:\A1"   'Folder name here<----
    'copying files to drop box folder
    strMoveToFolder = "H:\A2\"              'Folder name here-needs slash<-----
    Msg2 = "Moving/Copy Cancelled by User "
    Msg1 = "Moving/Copy from Here: " & objStartFolder & vbCrLf _
           & "To Here: " & strMoveToFolder & vbCrLf
    strStopGo = MsgBox(Msg1, vbOKCancel, "OST Utility-Move Files")
    If strStopGo = vbOK Then
    Set objFolder = objFSO.GetFolder(objStartFolder)
    Set colFiles = objFolder.Files
    For Each objFile In colFiles
                    cntFileID = cntFileID + 1
                    strFullPath = objFSO.GetAbsolutePathName(objFile)
         If instr(strFullPath,"002030_") > 0 Then  'Anchorage
              strNewFileName = "AK Anchorage v16 - LMB" & ".pdf"
         strMoveIt = "Yes"
         End If
         If instr(strFullPath,"005012_") > 0 Then  'CA Metro
              strNewFileName = "CA Airport Metro v30 - SPR" & ".pdf"
         strMoveIt = "Yes"
         End If
         If strMoveIt = "Yes" Then
             strNewPathName = strMoveToFolder & strNewFileName
                objFSO.CopyFile (strFullPath), strNewPathName
                'objFSO.MoveFile (strFullPath), strNewPathName
             strMoveIt = "No"
    		 cntMove = cntMove + 1
         End If
     ' ShowSubFolders objFSO.GetFolder(objStartFolder) 'Call Sub to Traverse deeper
     MsgBox Msg2, vbOKOnly, "OST Utility-Move Files"
    End If 'stop this now
    Wscript.Echo "Wow! It Finnished - " & Now() & vbCrLf & "Records Read: " _
                               & Right(String(6, "0") & CStr(cntFileID), 6) _
                               & vbCrLf & "Records Moved: " & CntMove
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/1087254

  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