Convert my VB into a Batch File

I got a VBScript that i created in order to change/update filenames in a specified folder based on a couple of IF factors. I was hoping to convert it into a DOS-Batch file for ease of being able to run it on a clients machine which doesn't have Visual Studio, just set a specified path for them then all they would have to do is run the batch any time to update files in the folder.

My VB skills are minimal and Batch Program skills next to none (just a few basic cmds), so I was hoping someone could so kindly translate it into Batch Format, or even open for simple alternative suggestions.


Dim objFSO
        Dim strCurrentFolder
        Dim objFolder
        Dim newFile
        Dim objFile
        objFSO = CreateObject("Scripting.FileSystemObject")
        strCurrentFolder = "I:\Project_Data\"
        objFolder = objFSO.GetFolder(strCurrentFolder)
        For Each objFile In objFolder.Files
            If UCase(Right(objFile.Name, 3)) = "PDF" And InStr(objFile.Name, "ABC") Or InStr(objFile.Name, "EFG") Then
                If Mid(objFile.Name, 14, 1) = "." Then
                    newFile = "2007-" & Left(objFile.Name, 8) & "LID" & Mid(objFile.Name, 8, 6) & ".pdf"
                    objFSO.MoveFile(objFile, strCurrentFolder & newFile)
                End If
            End If
        Next
        For Each objFile In objFolder.Files
            If UCase(Right(objFile.Name, 3)) = "PDF" And InStr(objFile.Name, "JKLM") Or InStr(objFile.Name, "EFGH") Then
                If Mid(objFile.Name, 15, 1) = "." Then
                    newFile = "2007-" & Left(objFile.Name, 9) & "LID" & Mid(objFile.Name, 9, 6) & ".pdf"
                    objFSO.MoveFile(objFile, strCurrentFolder & newFile)
                End If
            End If
        Next



Thanks
Jay
SES_TeamAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TimCotteeHead of Software ServicesCommented:
You don't need to convert this to a batch file. VBScript does not require visual studio installed in order to run. It runs within the Scripting Runtime context and uses either CScript or WScript to run. These are installed usually with internet explorer and / or the operating system itself. If you have a .vbs script file then it can be run on any machine where this is not explicitly removed or disabled. Most machines will have the scripting runtime already installed.

0
Arthur_WoodCommented:
Just to complement what TimCottee has correctly stated, if your code is simply saves as a file with the extension .vbs, then you can simply Double-click on that file, and it will run, automatically.

In addition, if you have any version of Windows newer than Windows 98, there is no version of DOS whatsoever on your box.  That has been completely integrated with Windows.

AW
0
SES_TeamAuthor Commented:
Excuse me for I mixed around my terminology. Your right about DOS, I was thinking Windows Batch (cmd prmpt) but said DOS-Batch. Also I said that I had VBScript when I actually have VB macro.

I appreciate the idea though, of course seems easier then coming up with a batch file. Can you please give me a little hint what I'm missing. I'm getting a compilation error - "Cannot use parentheses when calling a Sub".

What do I need to change?

Jay

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

sirbountyCommented:
I believe it's these lines...
objFSO.MoveFile(objFile, strCurrentFolder & newFile)
objFSO.MoveFile(objFile, strCurrentFolder & newFile)

remove the parentheses and it should work...
0
SES_TeamAuthor Commented:
I tried that after receiving the error msg and tracing down the line & char mentioned from the error. When I remove the parentheses from those lines I don't receive an error but then the MoveFile cmd doesn't work and nothing updates as it should.

It works when I run it in MS Visual Studio, just when trying to use it as vbs has some issue.
0
sirbountyCommented:
Let's try this...missing a couple of 'set's above...

Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")
strCurrentFolder = "I:\Project_Data\"
Dim objFolder:objFolder = objFSO.GetFolder(strCurrentFolder)
Dim newFile
Dim objFile
For Each objFile In objFolder.Files
  If UCase(Right(objFile.Name, 3)) = "PDF" And InStr(objFile.Name, "ABC") Or InStr(objFile.Name, "EFG") Then
    If Mid(objFile.Name, 14, 1) = "." Then
    newFile = "2007-" & Left(objFile.Name, 8) & "LID" & Mid(objFile.Name, 8, 6) & ".pdf"
    objFSO.MoveFile(objFile, strCurrentFolder & newFile)
    End If
  End If
Next
For Each objFile In objFolder.Files
  If UCase(Right(objFile.Name, 3)) = "PDF" And InStr(objFile.Name, "JKLM") Or InStr(objFile.Name, "EFGH") Then
    If Mid(objFile.Name, 15, 1) = "." Then
      newFile = "2007-" & Left(objFile.Name, 9) & "LID" & Mid(objFile.Name, 9, 6) & ".pdf"
      objFSO.MoveFile(objFile, strCurrentFolder & newFile)
    End If
  End If
Next
0
SES_TeamAuthor Commented:
I don't see what is really different besides the format of moving things around. And I get that error again pertaining to;

objFSO.MoveFile(objFile, strCurrentFolder & newFile)

Could it be that I'm calling it as a Sub(), in vbs do I need to call it using Function or something other then Sub()?
0
sirbountyCommented:
Try it by specifying objFile.Path instead of objFile

objFSO.MoveFile objFile.Path, strCurrentFolder & newFile
0
SteveGTRCommented:
Try this. It's in debug mode so it just echos out the command. To activate REM the set debug statement as annotated in the REM statement.

@echo off

setlocal

REM ** REM out the next statement to enable processing: REM set debug=echo
set debug=echo

set curFolder=I:\Project_Data
set fileMask=*.pdf

pushd "%curFolder%"

for /f "tokens=*" %%a in ('dir /b /a-d "%fileMask%" 2^>NUL ^| findstr /i "ABC EFG"') do call :PROCESS "%%a"

popd

goto :EOF

:PROCESS

set fileName=%~1

if not "%fileName:~14,1%"=="." goto :EOF

set fileName=2007-%fileName:~0,8%LID%fileName:~8,6%.pdf

%debug% ren "%~1" "%fileName%"

Good Luck,
Steve
0
SES_TeamAuthor Commented:
Sirbounty,

Thanks for the help, but I receive the same error when trying to specify objFile.Path instead of objFile.

Line:    16
Char:   73
Error:  Cannot use parentheses when callin a s Sub
Code:  800A0414

0
SES_TeamAuthor Commented:
Steve,

I have also tried your batch, while turning off echo it will run but doesn't seem to do anything. I don't recieve any msg, it runs then closes and nothing is update.

0
sirbountyCommented:
Line 16 appears to be

 If Mid(objFile.Name, 15, 1) = "." Then

What are you trying to accomplish there?  I'd suspect it's processing a file that's not 15 characters long...

I think you're better off using
if right(objfile.name,4"="."
or if just getting the extension
if objfso.getextensionname(file.name)="pdf"
0
SteveGTRCommented:
Let me place some debugging information in and have you paste the output:

@echo off

setlocal

REM ** REM out the next statement to enable processing: REM set debug=echo
set debug=echo

set curFolder=I:\Project_Data
set fileMask=*.pdf

pushd "%curFolder%"

for /f "tokens=*" %%a in ('dir /b /a-d "%fileMask%" 2^>NUL ^| findstr /i "ABC EFG"') do call :PROCESS "%%a"

popd

goto :EOF

:PROCESS

echo File name: %~1

set fileName=%~1

if not "%fileName:~14,1%"=="." goto :EOF

set fileName=2007-%fileName:~0,8%LID%fileName:~8,6%.pdf

%debug% ren "%~1" "%fileName%"
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SteveGTRCommented:
Just love the grading system here... Makes perfect sense --- lol
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.