Batch file to move a number of files, then replace each of them with one file of another type while letting them keep their original name - batch-file

First off I want to say that
-I didnt ever create a batch file yet, but I am really willing to learn
-I am not even sure if what i want to do is possible with a batch file
What i want to do is the following:
I want to replace a number of files of one file type in a folder each with one and the same file of another file type. In doing this, i want the "replaced" files to keep their original name except for the "replacer" file's extension. I am not talking about file conversion, this is about replacing several different files each with one and the same file, so each of them will look the same later, just with different names and the file extension of the "replacer" file. All of the files inside the folder are to be treated this way, there are no exceptions.
So it looks something like this:
Folder 1 Folder 2
10000000.tga------------->10000000.png (looks like replacer.png)
10000001.tga------------->10000001.png (looks like replacer.png)
10000011.tga------------->10000011.png (looks like replacer.png)
I really hope that my description is sufficiently precise, if not so, I am of course willing to give any information needed. I found parts of what i need (e.g. a loop for files in a folder, an order to replace one file with another file) but I am unsure of how to combine them at all, let alone to achieve what I actually wanted to do.
Any help is greatly appreciated :)

for %%i in (*.tga) do (
copy "replacer.png" "%%~ni.png"
del "%%i"
)
see for /? for details about the %%~.. syntax

Related

Update file across multiple folder locations?

I need something that can copy a specified file any and everywhere on my drive (or computer) where that file already exists; i.e. update a file. I tried to search this site, in case I'm not the first, and found this:
CMD command line: copy file to multiple locations at the same time
But not quite the same.
Example:
Say I have a file called CurrentList.txt, and I have copies of it all over my hard drive.  But then I change it and I want all the copies to update.  So I want to copy the newer one over all the others.  It could 'copy if newer', but generally I know it's newer, so it could also just find every instance and copy over it.
I was originally going to use some kind of .bat file that would have to iterate over every folder seeking the file in question, but my batch file programming is limited/rusty.  Then I looked to see if xcopy could do it, but I don't think so...
For how I will use it most, I generally know where those files are going to be, so it actually might be as good or better if I could specify it to (using example), "copy CurrentList.txt, overwriting all other copies wherever found in the C:\Lists folder and all subfolders".
I would really like to be able to have it in a context menu, so I could (from a file explorer) right click on a file or selected files and choose the option to distribute it.
Thanks in advance for any ideas.
Use the "replace" command...
replace CurrentList.txt C:\Lists /s

How to randomize file order on folders with a batch file

am trying to get a batch file to help me randomize files.
Files are videos/music/text/doc
To be more specific, lets say am having the following files on a folder named like this:
3020_1
3020_2
3020_3
3020_4
3020_5
6031_1
6032_2
5013_1
6060_1
Windows will sort them as above, and i would like to get a folder with the above files to appear randomly.
Can you guys help me out :)
I am sure you are aware of the fact that the order of appearance of files in a Windows folder depends on the sort option you have chosen. Assuming you still want to do this in a given sorted view and you are OK renaming files, you can try the ren command to do this. Find more details here
ren 3020_1 3020_2
Since you want this to be random, you will have to add a bit of logic to get a random file name.
%RANDOM% will give you a random number every time you execute it. More information on that is available here
Hope this gets you move further

Using a batch file to copy multiple files with the same name, and past into new folder with differing names

I have a long list of files that are auto-produced every month. they'll all have the same file name, with a sequential file extension like this:file.001, file.002, file.003
Each file has differing information, despite having the same name. What I need to do is copy them from their home directory and paste them into a new directory with names that reflect their purpose, and as text files, like this: Budget.txt, Expense.txt, Retention.txt
Is it possible to do this with a batch file? I've been unable to find a method that works. Any help would be appreciated.
EDIT: I've tried that solution, and it works as far as it goes. the frustrating thing is that the extensions are not always the same, but always sequentially numbered.

How to copy the names of the subfolders in a folder, so to use them in a batch program (command line)?

I need to check the files of a versioned system. To do that, I need to write a batcha program so to compare the contents of several folders containing the repositories.
So, my question is: how can I "read" the names of all the subfolders inside a folder, so to use these names later to find subfolders having the same names in a different repositories?
I suppose I may use DIR to print on the screen a list of these names but I don't know how to write it on a text file and then read it. Moreover, I should edit this kind of list, anyway.
Any suggestions or new ideas to solve this problem?
I thank gratefully who ever will answer.
it seems that you can get the subfolders using batch file from perl as follows:
system("start C:\\Temp\\mybatchfile.bat");
or you might try to pass your command suggested by #Stephan straight to system and try to handle what it is returned.

XCOPY exclude list ignored after first exclusion

I have a batch file I've created which uses xcopy to copy a dir, and child dirs, and merge them into one file. (ie. all my modulised development css stylesheets merged into one production stylesheet).
Everything is good, apart from the fact that when I reference the excludelist.txt, it only excludes the first line, and not the subsequent files I want excluded.
Anyone fancy a crack at this? You'd be most helpful.
Here's the code:
XCOPY C:\xampp\htdocs\PROJECT\css\*.* C:\temp /S /I /Y /EXCLUDE:C:\xampp\htdocs\PROJECT\exclude.txt
...and inside my exclude.txt is...
1.css
2.css
3.css
4.css
5.css
///// I know the code works (to an extent) because it is infact excluding file 1.css -- just not the ones below it. Am I right to put each exclusion on a new line?
I use the following,
xcopy "C:\users\dad\*.*" dad /s /d <yesnoyesno /EXCLUDE:excluexclu 1>cop.txt 2>err.txt
as somewhere on the web I saw a note to the effect that the /Y switch could not be used directly with an exclude file.
What I wanted to point out here, was the useful output files 1 & 2, which detail the success & failure issues.
Mine shows only success.
The short answer: Create a new text file, type the entries and save the file.
The longer explanation: I ran into this very issue on a Windows 2008 server today. I tried all kinds of things to get it to work. Forced notepad to save the file as ANSI, Unicode and UTF-8 but all of them had the same problem. Finally I started thinking about the fact that I put the file on the server via FTP and it's quite likely that FTP tweaked the file format. I created a new text file on the server, typed all the same entries in the new file and now it works.
I had a similar problem. I was trying to exclude all files with a certain extension in the root folder and any sub-folders and it didn't work. The reason was I was putting *.pdb instead of just .pdb. The newline/carriage return thing was a total red herring for me.
So my file just looked like:
.pdb
.obj
.vb
.cs
You seem to be using xcopy correctly - each exclusion file (or match depending on wildcards) should be on a new line within the file. So far I've been unable to reproduce the behaviour you're experiencing.
Is the exclude.txt listing you've given above a test file, or are they the actual css names?
What are the names of the other files that your batch file is supposed to copy?
Edit:
That the xcopy is failing to exclude further files after a single match is giving me most pause. I thought it might be to do with the type of carriage-return that was used in the exclude file, but xcopy handles unix-style carriage-returns just fine.
Can you re-verify that the correct exclude file is being used?
Try forcing it to save with ANSI encoding on your text editor.
I was having a similar issue and that did it.

Resources