Need Batch File Help

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Agolfnut

Thread Starter
Joined
Jan 28, 2013
Messages
1
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
002030_00016_YP_000_00006_0_PAG.pdf

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

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

005012_00030_YP_000_00003_0_PAG.pdf

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?
 
Joined
Jan 15, 2013
Messages
87
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
 
Joined
Jun 8, 2001
Messages
2,583
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.


Code:
'---------------------------------------------------------------
'-- 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
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
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<-----
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
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
   
  Next
 ' ShowSubFolders objFSO.GetFolder(objStartFolder) 'Call Sub to Traverse deeper
  
 Else
 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
'--------------No-SubRoutines---------------------------------------
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

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 807,865 other people just like you!

Latest posts

Members online

Top