PPRuNe Forums

PPRuNe Forums (https://www.pprune.org/)
-   Computer/Internet Issues & Troubleshooting (https://www.pprune.org/computer-internet-issues-troubleshooting-46/)
-   -   a fast way to replace 1000+ files? (https://www.pprune.org/computer-internet-issues-troubleshooting/359178-fast-way-replace-1000-files.html)

Massey1Bravo 23rd Jan 2009 09:41

a fast way to replace 1000+ files?
 
Does anyone know of a command or software that can copy and replace multiple files? I have about 1600 different bitmap files in a folder that needs to be replaced by copies of a single white bitmap, and it will take some major effort to copy and rename every single file manually.

airship 23rd Jan 2009 12:01

Not sure about the utility of

...replaced by copies of a single white bitmap...
:confused: but I use ThumbsPlus whenever I need to alter multiple images in the same way. It has a great "batch-process" function for multiple files, allowing easy conversion to/from most image formats; renaming - keeping the old file name, adding a prefix or suffix, numbering options - lots of ; changing image resolution and resizing; image enhancements, cropping etc.

Pretty sure that it'll do what you want. But there's probably a cheaper way to do it in MS-DOS...?! ;)

DUS SLF 23rd Jan 2009 23:53

2nd attempt, 1st one crashed the thread and got deleted.

Assuming you are using Windows and have Excel or the OO counterpart, there is a away using DOS commands.

It's a bit annoying but there's nothing else I could think of except googling for a tool that does the same with less legwork.

1) Create a .txt file in your target folder (the one with the 1000+ files) and rename it to something like step1.bat. Windows will warn you about the extension, but it's okay.
2) Right-click on the text file and edit it to contain this command: dir /B >filelist.txt
3) Save the file and close it.
4) Double-click step1.bat to run it. You'll have a file list called filelist.txt in no time.
5) Open filelist.txt in Excel. Excel will ask a couple of questions but the answers should be obvious. You now have the list of target names on column A
6) Move the target names to column C, fill column A with xcopy and column B with the name of your source file, including extension. Fill column D with /Y unless you want to confirm each overwrite. Each line in your Excel file should look something like this: Xcopy sourcename.bmp targetname.bmp /Y
7) Save this as step2.txt in your target folder (make sure file format is still .txt and not XLS) and then rename to step2.bat using the Explorer or something like that
8) Copy the source file to the target folder
9) Read this warning: if all was done right and all goes according to plan running step2.bat will overwrite your original bmps. There is no way to recover them once the batch file was run. Better create a backup first.
10) Run step2.bat, check all was copied ok and clean away the temporary files

That's it, sounds more complicated than it is, really. Feel free to PM me for clarification.

However, if someone knows a better way, I am eager to hear it as I use the above process a lot.

Massey1Bravo 24th Jan 2009 01:36

It worked! Many thanks DUS SLF! :ok:

I thought about the Xcopy command but I didn't know about the Excel trick.

In rerum natura 6th Feb 2009 19:27

Late as ever.
For those without Excel (a brilliant piece of lateral thinking BTW).

First ensure that the new file blank.bmp has been copied to the existing oldpix data folder & then create the following batch file (my_name.bat) in a convenient location (e.g. root), modifying folder/file names and paths as necessary.


MD c:\newpix
CD c:\oldpix
MOVE blank.bmp c:\newpix
DIR /B > c:\newpix\filelist.txt
CD c:\newpix
FOR /f %%n IN (filelist.txt) DO COPY c:\newpix\blank.bmp c:\newpix\%%n
I think this will work but no promises as I only used a set of 30 files to test it. Note, the FOR DO statement is all one line.

Saab Dastard 6th Feb 2009 21:57

A small addendum to the pipe command:

If you wish to pipe (>) the output of a command to an existing file just use >> to the filename.

SD

Mac the Knife 10th Feb 2009 04:32

rerum - I think you'll need a "shift" command

Batch files - Command line parameters

:ok:

Shunter 10th Feb 2009 06:18

This is a prime example of why downloading bash for Windows and the Unix Utils (all free) is very useful. 1 line, no hassle.

for i in `ls c:\oldpix` ; do cp c:\newpic.bmp c:\oldpix\$i ; done

:ok:

Shunter 10th Feb 2009 06:20

This is a prime example of why downloading bash for Windows and the Unix Utils (all free) is very useful. 1 line, no hassle.

Unfortunately I can't paste it, due to the idiotic smiley crap which messes with everything in sight.

stickyb 10th Feb 2009 10:24


Originally Posted by Shunter (Post 4708387)
This is a prime example of why downloading bash for Windows and the Unix Utils (all free) is very useful. 1 line, no hassle.

for i in `ls c:\oldpix` ; do cp c:\newpic.bmp c:\oldpix\$i ; done

:ok:

If you repost and tick the option box "disable smilies" all the crap you complain about will disappear and we can learn. I'll do it for you this time

In rerum natura 10th Feb 2009 18:31

Mac
 
The last time I wrote batch files in anger I had to type copy con: my_file.ext at the DOS prompt and terminate the text with ^Z and a quaint thing called a carriage return (anything was better than edlin). But my %%n is a variable and not a parameter so I don't think the shift command is syntactically relevant (chemo brain...I even lost my specs in the snow...so I am happy to stand corrected). SD? As I said, I did test the 'program' after I scribbled it down and before posting. Very quick and dirty, no errorlevel, if exist, if not exist checks and no clean up afterwards. But non-destructive, at least.

Of course, the source and destination paths and file names could be passed as parameters (%1..%9) from the command line in which case the shift command might become pertinent (that's something for you to do, Homer, find that out). But all the meat is in the last line (which is essentially the Bash command suggested by Shunter), which was sufficient to answer the OP's question. Thanks for the page linked to, though, which I have saved to disk and will study later; Microsoft's help page for XP batch file commands is very limited in its scope. Looks like you're expected to part with even more money for books which used to be supplied with the OS (GW Basic reference, command line reference, batch file reference). For a really hard core batch file (whose workings I don't for a moment pretend to understand) have a look at this:
Stupid Coding Tricks: A Batch of Pi - The Daily WTF

FOR /f %n IN (filelist.txt) DO COPY /Y blank.bmp %n
can be entered at the command prompt in source=target directory but is destructive.
IRN

RandiR 25th Mar 2009 21:07

Script to copy over 1600 bitmap files
 
Massey1Bravo has the following requirement:


Does anyone know of a command or software that can copy and replace multiple files? I have about 1600 different bitmap files in a folder that needs to be replaced by copies of a single white bitmap, and it will take some major effort to copy and rename every single file manually.
Hi Massey1Bravo:

I will write a script for you.

I will assume the following.


1. You have over 1600 bitmap files in the folder "C:/Bitmaps" and, possibly, its subfolders. Their file extension is .bmp.
2. You want to copy over each of these files a single white bitmap stored at "C:/MasterBitmap.bmp".
Here is my script. It is written in biterscripting. (Download biterscripting free, if you don't have it. The installation instructions are at http://www.biterscripting.com/install.html . It is excellent for doing a lot of things like this.)

(I will admit that I am following one of the sample scripts that came with biterscripting - so this is not all my original work.)

Code:


 
# Collect a list of files that are to be copied over.
car str filelist ; find -r -n "*.bmp" "C:/Bitmaps" > $filelist
 
while ($filelist <> "")
do
    # Get the next file.
    var str file ; lex "1" $filelist > $file
    # The full path name of the file is in $file. Delete, then copy.
    system del ("\""+$file+"\"")
    system copy "C:/MasterBitmap.bmp" ("\""+$file+"\"")
done


Save the script in some file (say, C:/X.txt), start biterscripting and run the command

Code:

script "C:/X.txt"
That's it.

Let me know if this works for you.

Randi

Peter Fanelli 26th Mar 2009 10:42


I have about 1600 different bitmap files in a folder that needs to be replaced by copies of a single white bitmap
Something you need to hide?

:=


All times are GMT. The time now is 23:06.


Copyright © 2024 MH Sub I, LLC dba Internet Brands. All rights reserved. Use of this site indicates your consent to the Terms of Use.