copy file & rename

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
SpyShadow
Posts: 7
Joined: 12 Apr 2012 08:42

copy file & rename

#1 Post by SpyShadow » 12 Apr 2012 08:47

I am new to batch scripts. I need help on making a batch script to do the following.

car.vtx - make a copy of this file 2x
car.dx80.vtx - 1st copy of file with dx80 added
car.dx90.vtx - 2nd copy of file with dx90 added

ending result is 3 files, 1st is the original but with 2 extra's that are named different. If script finds a file with same name, as in a file with dx80 or 90, overwrite it.

The idea here is there is a folder with many .vtx files, some have the dx80 extension and some do not. I need a script to run and create the dx80 and 90 files from existing vtx files but keeping the file name.

hopefully someone can help me out because I really hate to rename 4,000 files by hand.

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: copy file & rename

#2 Post by Fawers » 12 Apr 2012 09:09

What is the path you want it to be copied to?

And is this .vtx file a binary file?

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: copy file & rename

#3 Post by Fawers » 12 Apr 2012 09:19

Anyways, this should do it:

Code: Select all

@echo off
set fname=car.vtx
set pth=
set n=1
:CopyLoop
if [%n%]==[2] set fname2=%fname:~0,3%.dx80.%fname:~-3%
if [%n%]==[3] set fname2=%fname2:80=90%
copy [/b] %fname% "%pth%.\%fname2%"
if [%n%]==[3] exit /b
set /a n+=1
goto CopyLoop


Just don't forget to:
1) set pth as the path you want the files copied to (without quotes);
2) remove the /b (or the brackets surrounding it) depending on whether the file is binary or not.
2.1: remove [brackets] if file is binary;
2.2: remove whole [/b] switch if file is not binary.

Edit {
SpyShadow wrote:car.vtx - make a copy of this file 2x

Just saw you want only 2 copies of it instead of 3.

But whatever, foxidrive's code is better than mine. Use his.
}
Last edited by Fawers on 12 Apr 2012 09:55, edited 2 times in total.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: copy file & rename

#4 Post by foxidrive » 12 Apr 2012 09:42

This should work but is untested. Try it in c:\test with some copies of the files and folders.

Code: Select all

@echo off
for /f "delims=" %%a in ('dir *.vtx /b /s') do (
echo processing "%%a"
copy /y /b "%%a" "%%~dpna.dx80%%~xa" >nul
copy /y /b "%%a" "%%~dpna.dx90%%~xa" >nul
)
echo done
pause
Last edited by foxidrive on 12 Apr 2012 09:52, edited 1 time in total.

SpyShadow
Posts: 7
Joined: 12 Apr 2012 08:42

Re: copy file & rename

#5 Post by SpyShadow » 12 Apr 2012 09:45

number 1,

set fname=car.vtx

all files are not car.vtx
I like to do this to all files with the extension of .vtx basicly.

The directory would be the folder that the batch file is in if that is possible.

what do you mean by binary or not?

thanks for the fast reply.

and I be testing out the code

------------------------------------------------------------------

I this tested out the code above posted by foxidrive.

we are missing the dot.

as in filename.dx80.vtx

besides that, script looked like it worked

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: copy file & rename

#6 Post by foxidrive » 12 Apr 2012 09:53

SpyShadow wrote:I this tested out the code above posted by foxidrive.

we are missing the dot.

as in filename.dx80.vtx

besides that, script looked like it worked


Try it again, I added the dot.

SpyShadow
Posts: 7
Joined: 12 Apr 2012 08:42

Re: copy file & rename

#7 Post by SpyShadow » 12 Apr 2012 10:00

ok that worked. Now I did a different test, like let's say if there was a file with...

filename.dx80.vtx

in folder allready and I ran script and here is what it did.

filename.dx80.dx90.vtx
filename.dx80.dx90.vtx

that was from only 1 file with name allready. if there was 2, it probably would created 2 more. Anyway to make it Skip a file allready there or overwrite it?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: copy file & rename

#8 Post by foxidrive » 12 Apr 2012 10:12

Try this on some sample files (untested)

Code: Select all

@echo off
for /f "delims=" %%a in ('dir *.vtx /b /s ^|find /i /v ".dx" ') do (
echo processing "%%a"
if not exist "%%~dpna.dx80%%~xa" copy /y /b "%%a" "%%~dpna.dx80%%~xa" >nul
if not exist "%%~dpna.dx90%%~xa" copy /y /b "%%a" "%%~dpna.dx90%%~xa" >nul
)
echo done
pause

SpyShadow
Posts: 7
Joined: 12 Apr 2012 08:42

Re: copy file & rename

#9 Post by SpyShadow » 12 Apr 2012 10:19

thanks guys. That works perfectly. I have one more question to ask. Is it possible for a batch file to be able to modify a byte within a file?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: copy file & rename

#10 Post by foxidrive » 12 Apr 2012 10:21

A binary 'change' utility is generally the way to go about that.

debug can do it but filesize is limited and it is arcane these days.

Describe the change a little better and perhaps some other ideas will come to mind.

SpyShadow
Posts: 7
Joined: 12 Apr 2012 08:42

Re: copy file & rename

#11 Post by SpyShadow » 12 Apr 2012 10:27

ok. Well, there are these MDL files that go along side these vtx file. MDL = Model file. I am trying to restore the MDL file to an older version and that restoration is by changing 1 byte. I know exactly the hex value and position that needs to be changed which is only a few bytes in the header of the file.

change what ever value at first line in file from IDST1 to IDST,

this will make the MDL file work in an older version of the game engine. You guys did the most hardest accomplish which is the copying of vtx files and renaming.

I managed to make a visual studio program that does it but I still can't even get that to go automatic like the batch script you guys made. App I got working is in C# and I this used beginner tutorials I found to get it working. Took several hours. But as I said, on the app, I have to open each file individual to do it which will take a long time.

so simply, change 1 byte to a new value. The files can be opened in a txt editor too.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: copy file & rename

#12 Post by foxidrive » 12 Apr 2012 10:43

Can you confirm that the MDL files are plain text files and that you want the first line to change from whatever it currently is to

IDST,

Does that include the comma?


What is the average length of a Model file? Less than 60K lines?

SpyShadow
Posts: 7
Joined: 12 Apr 2012 08:42

Re: copy file & rename

#13 Post by SpyShadow » 12 Apr 2012 10:50

I can open the mdl file in notepad.exe and here is a sample of what it shows on the first line....

IDST0 ¡˜jprops_equipment\cooler.mdl

now sometimes it can be different things but no matter what, the IDST is allways there.

IDST,
IDST0
IDST1
IDST2

as you can see, the last digit on IDST is allways changing to something else for a different version. now the file extension of the files are .mdl but can be read in notepad.exe

they need be changed to IDST, in the files.

I think every mdl file is at different sizes. All that needs to be modified is one letter at Ln 1, Col 5

I uploaded a sample mdl file for ya guys if ya want to look at it and see for ya selves.

http://dl.dropbox.com/u/58614432/New%20WinZip%20File.zip

hope that helps

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: copy file & rename

#14 Post by foxidrive » 12 Apr 2012 10:55

They are binary files.

It can be changed using a batch file but you'll have to download a utility. I'll see what I can find.

SpyShadow
Posts: 7
Joined: 12 Apr 2012 08:42

Re: copy file & rename

#15 Post by SpyShadow » 12 Apr 2012 10:59

foxidrive wrote:They are binary files.

It can be changed using a batch file but you'll have to download a utility. I'll see what I can find.



That would help out greatly. If ya can't find anything, I will ask around on the C# forums and seeing if I can find a programmer to make a small app that can change that 1 byte in a folder directory and sub directories.

The reason on why I am doing this is trying to generate thumbnails of the models. The game gmod can read the mdl files but not newer versions. Plus editing several thousands of files by hand will be a big pain and I'm not getting younger.

Post Reply