Computing.Net > Forums > Disk Operating System > Help with DOS Batch renaming

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Help with DOS Batch renaming

Reply to Message Icon

Name: Segfau|t
Date: June 8, 2002 at 14:11:21 Pacific
Comment:

I am trying to rename some files, only if: "copy *.txt ..\50-*.txt" worked. Basically, I have a GROUP of directories (I have about 15 Groups, each with about 150 directories, each directory has a descriptor file and a folder of the same name (without the .txt).

ie: C:\GroupA\50\canada.txt describes what C:\GroupA\50\Canada\*.* is. (under 50\ there might be canda.txt, usa.txt, mexico.txt, etc...

Since over all I have about 15 Groups X 150 Dirs X ~10 SubDirs (22500 files alltogether) it needs to be repetitive and recursive.

the file names are 90% different but repetition does occure (ie: I may have C:\GroupA\50\Canada.txt and C:\GroupA\11\Canada.txt and C:\GroupA\97\Canada.txt).

I would like to take (respective to listed above) and create
C:\GroupA\50-Canada.txt, C:\GroupA\11-Canada.txt, C:\GropuA\97-Canada.txt)


I have "first.bat" which is called from the Group (GroupA) and it says (manually made, would be nice to make automatically):

call second.bat 01
call second.bat 02


and I want (dynamic) second.bat to create a (static) third.bat which then it will execute:

ie:

second.bat says

dir %1\*.txt > %1.bat blah.txt" how can I insert my own text into blah.txt so that I can create a functioning batch file. (IE: similarly to C/C++ when it's:

cout << "this is my variable: " << var << "!" << endl;

If there is a % variable that will keep full name and simply build onto the beginning - I would gladly work with that.


Any help is greatly appreciated,
Thanks,
-- Ian



Sponsored Link
Ads by Google

Response Number 1
Name: Secret_Doom
Date: June 8, 2002 at 18:07:41 Pacific
Reply:

Hmmm... Your doubt is not very clear to me.

Please confirm this: You have the following generic directory path:

C:\GROUP\DIR\SUBDIR
ex:
C:\GroupA\50\Canada
C:\GroupB\25\Brazil

You want to get all files with .txt extention under each DIR (not the ones under the SUBDIRs) and copy to the GROUP which contains that DIR, with the name of the DIR (from where it came) followed by "-" and the original filename.

Example - let's say you have:
C:\GroupA\50\Canada.txt
that file would be copied to
C:\GroupA\50-Canada.txt

Is that it ??
If not, please explain better.

Once I have understood you I can help.

-- Secret_Doom - Leonardo Pignataro --

secret_doom@hotmail.com
www.batch.hpg.com.br


0

Response Number 2
Name: Secret_Doom
Date: June 8, 2002 at 18:50:47 Pacific
Reply:

Your OS (Operational System) would also be a valuable information.

-- Secret_Doom - Leonardo Pignataro --

secret_doom@hotmail.com
www.batch.hpg.com.br


0

Response Number 3
Name: Segfau|t
Date: June 8, 2002 at 21:38:19 Pacific
Reply:

Secret_Doom:

Yes, Your above interpretation is correct.

the OS in question currently is WinXP/2K


Further tinkering led me to two different methods of solving this problemL


A) a copy statement that will allow me to do as above mentioned:

C:\GroupA\50\Canada.txt
would be copied to
C:\GroupA\50-Canada.txt


B) a statement that will allow me to parse file, line by line, created by "dir *.txt /b" and the value that will be read into a batch file as a % value.


Thanks for the help,
-- Ian


0

Response Number 4
Name: Secret_Doom
Date: June 9, 2002 at 13:38:36 Pacific
Reply:

The following batch script should work for Win2K/XP:

@echo off
for /d %%a in (*) do (
cd %%a
for /d %%b in (*) do (
cd %%b
for %%c in (*.txt) do (
:: Remove 'echo.{demo}' to activate script
echo.{demo}copy %%c ..\%%b-%%c
)
cd..
)
cd..
)

It should be runned from the root directory (or the directory which contains the GROUPS directories)

This script is de-activated. Run and check the output to the screen: if when runned it would take the desired effect, then activate the script (read commented line).

I only tested it in Win95Cmd.exe, which is some sort of a Win2000's CMD.exe emulator for windows 95.

Keep in mind that such script will *NOT* work on any DOS-based system (such as Dos6.22 and Windows9x).

-- Secret_Doom - Leonardo Pignataro --

secret_doom@hotmail.com
www.batch.hpg.com.br


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


GHOST -> DOS -> USB dosstart.bat



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Help with DOS Batch renaming

SOS! Need help with DOS Batch problem www.computing.net/answers/dos/sos-need-help-with-dos-batch-problem/7906.html

HELP ME WITH DOS BATCH FILES LINES PLEASE www.computing.net/answers/dos/help-me-with-dos-batch-files-lines-please/2496.html

Help with DOS 6.22 Installation www.computing.net/answers/dos/help-with-dos-622-installation/7169.html