AllExperts > Visual Basic 
Search      
Visual Basic
Volunteer
Answers to thousands of questions
 Home · More Visual Basic Questions · Answer Library  · Encyclopedia ·
More Visual Basic Answers
Question Library

Ask a question about Visual Basic
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Robert Nunemaker
Expertise
String manipulation, Database access and usage, Class creation, and encapsulation are my strong suits. Active X Controls and DLL`s also. Although I don`t deal with Crystal - frankly because I don`t like it; I prefer to do things manually.

Experience
Employment history: Programmed with the Air Force for 15 years, and have continued in the private sector for the past 1 year. Used VB (all versions) for the past 8 years.

Organizations: MCP and MCSD certified.

Education: Computer Science Bachelor degree.

Awards: MCP and MCSD certified.

 
   

You are here:  Experts > Computing/Technology > Basic > Visual Basic > Batch commands

Visual Basic - Batch commands


Expert: Robert Nunemaker - 1/7/2009

Question
Hey Robert,

First of all, my question isn't in a field you list as an expertise so you are excused for deleting it if you don't know the answer.  Equally I won't be giving any negative feedback for bad answers either!  With that said, I'm a novice Java programmer myself and its not uncommon for a programmer to have familiarity with other languages, so I felt it was worth asking just in case :).

Basically, I'm trying to write a very simple batch program to remove the first x characters from a whole bunch of files.  While I know there are nice utilities around to do this for me, I'm treating it as an learning exercise... especially since I've been at it for several hours now and I just plum want to figure out what I'm doing wrong!

Here is the code I have stitched together:

FOR /R "P:/Music/" %f IN (*.*) DO (
set output=%f%
set output=%output:The =%
echo.%output%
)
pause

The idea is that I save that as a .bat file, run it, and then hey presto the names of all the files in that directory are printed to the cmd window but lose the string "The ".  The 'pause' at the end is meant to hold the cmd window open so i can see the print (aka echo) messages to verify it all worked. However, it doesn't!

There's two problems.
1. The pause isn't pausing, which is causing the cmd window to appear and disappear in a flash.  I think thats because the prior code is buggy.
2. There's something wrong with my variables.  Only the final file name is displayed, and with additional characters from my code (%, :The, and so on).


Heeeeeeeeeelp!


All the best and thank you for being an allexperts volunteer!

Daf

Answer
I'm sorry, but I'm not a batch file Guru as much as I used to be.

However, a few things.

- When you want the PERCENT symbol to be interpreted as such, you need to have 2 of them.  So in your FOR loop, you need:
FOR /R "P:/Music/" %%f IN (*.*) DO (
- The pause isn't working because it isn't DOS per se.  It is a DOS emulator.  So, you need to create a CMD file (i.e. FIXFILES.CMD) with the line:
START Drive:\Folder\File
i.e. START C:\TEMP\FIXFILES.BAT


Add to this Answer   Ask a Question


 
User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright  © 2008 About, Inc. AllExperts, AllExperts.com, and About.com are registered trademarks of About, Inc. All rights reserved.