1.

Solve : Replace integrity of many files with one?

Answer»

Good morning, I have a very daunting task before me that I really could use some help with. I have 652 files named in an increasing sequence “startofthefilename000_000” the 000_000 change. My problem is I need to take one file and replace the integrity of the 652; while keeping their naming convention of course.

I have a few years programming experience, and networking but its been years since I have touched dos. I have windows XP, is there anyway I could use Replace with wild cards or some other command from the windows Command Prompt to do this? Or could a batch file be able easily accomplish this?

I would greatly appreciate any help,Could you please explain what you mean by the "integrity of the 652"? In fact, could you please explain much more clearly what it is that you want to do?

I have 6 folders, with a total of 652 files. To simplify things I'll just deal with one.

The folder is called small and it has 310 files in it are "small00_00" followed by "small00_01" up through "small00_09" then next file is "small01_00" this goes up to "small29_09". They are different color textures, I need to bland things out by replacing each of them with the same color. So I meant integrity as the files contents being changed.Thank you. Please confirm that I understand properly.

You have a number of folders. Each folder contains a number of files. They are different. You want to change them so all the files have the same contents as each other, but preserving their former filenames?

Correct, you hit the nail right on the head. So... you want to do this, I think?

For each file in a folder:

delete (Query: or rename?) the file?
create a new file with the same NAME
place in that file some standard contents (Query: unique to that folder, or the same for all 652 files?)

There are a number of tools that can be used to do this. A batch file, or a Visual Basic Script (VBS), or another tool such as awk or perl or others still. I know how to do this sort of thing in a batch file, but other people can probably suggest much more elegant SOLUTIONS using the other tools I have mentioned. Please, THEREFORE, state your preference.

Great to hear, I dislike VB, a batch file would work well.

Quote from: Salmon Trout on July 21, 2009, 10:35:12 AM

(Query: unique to that folder, or the same for all 652 files?)

Unique to that folder.So you might have a folder called small and a file called small_new (in that folder?) and you WISH to MAKE all the other files identical to that?

That would be perfect!You did not answer whether you wish to destroy or preserve the previously existing files.
I apologize, I would wish that they are destroyed. Suppose you call this file MakeAllSameAs.bat and

place it in a folder containing the files to be altered and the file to be copied to each

open a command window in that folder and type its name followed by the name of the file to be copied e.g.

MakeAllSameAs "small_new"

Code: [Select]@echo off
set repfile=%~1
echo Replacement file: %repfile%
for /f "delims=" %%F in (' dir /b ^| find /v "%repfile%" ^| find /v "MakeAllSameAs.bat" ' ) do (
Echo Replacing %%F
del "%%F"
copy "%repfile%" "%%F"
)


It works, thank you very much. This is very exciting!!!Quote from: Salmon Trout on July 21, 2009, 11:48:59 AM
Suppose you call this file MakeAllSameAs.bat and

place it in a folder containing the files to be altered and the file to be copied to each

open a command window in that folder and type its name followed by the name of the file to be copied e.g.

MakeAllSameAs "small_new"

Code: [Select]@echo off
set repfile=%~1
echo Replacement file: %repfile%
for /f "delims=" %%F in (' dir /b ^| find /v "%repfile%" ^| find /v "MakeAllSameAs.bat" ' ) do (
Echo Replacing %%F
del "%%F"
copy "%repfile%" "%%F"
)



you can use findstr, then you don't need to pipe to find 2 times
Code: [Select]for .... ( dir /b .. | findstr /v /c:string1 /c:string2 ) do (... )


Discussion

No Comment Found