To many image files on my server

Posted on 2006-06-19
Last Modified: 2010-04-06
I have over 4000 images in each of several folders and only need about 2000 of them.  As we grow and add new products, the difference is going to get larger.  I fear the server will start to slow down when displaying the image files.  

Is there a windows program that would do a compare from an imported file list and either delete or move images not in the imported file list?


Question by:stroudtx
  • 7
  • 3
  • 2
  • +1

Expert Comment

ID: 16942818
You could write a macro in vba that easily do the trick.

Author Comment

ID: 16942890
If I knew how to program in VBA. I do know asp vb, but I'm sure they are way different. I was hoping for an off the self solution.

Expert Comment

ID: 16942991
OK, I will try something in ASP.
Does this imported file list contains the URL of the image files or the server path?

Author Comment

ID: 16943050
I can parse it out either way. I could even move just the files that are in the db and thus leave the old ones.
LVL 19

Expert Comment

ID: 16945239
>I could even move just the files that are in the db and thus leave the old ones.

A fairly simple batch file could do this job. Something like this:
   for /F %%I in (moveme.txt) do move %%I blah
where moveme.txt is a file listing the paths to the files you want to move, and blah is the folder to move 'em to.
There's a lot of power in the windows command prompt these days, it's much more flexible than it used to be.


Author Comment

ID: 16945276
interesting.  I've never run a batch file before and how would it know to go to the next line in the txt file.  Would they be seperated by lines, commas, tabs, etc?
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

LVL 19

Expert Comment

ID: 16947536
>I've never run a batch file before and how would it know to go to the next line in the txt file.
The ability to read lines from a file is built-in to the FOR command. The file names would be separated by returns (each file on its own line.) For example, moveme.txt might look like this:


With the command extensions available in Windows XP and 2000, you could even copy the directory structure from one drive to another.

You can read more about the FOR command and how to use it by typing HELP FOR at a command prompt.


Author Comment

ID: 16948620
I checked it out so somewhat understood.   I'm not a dos person so I don't know any commands nor the syntax.  Is there a web site or some reference point to go to?  

Author Comment

ID: 16965908
can anyone help me with the syntax here?

LVL 19

Expert Comment

ID: 16966165
Did you read the HELP FOR text? That gives a very concise explanation.
Go to a Windows command prompt. Type HELP FOR

Here's a reference for many common Windows batch commands, maybe it will be clearer.

>can anyone help me with the syntax here?
What exactly do you want to happen? If you give me a specific task you want to accomplish, I can help you create a batch file to do it. Do you want to move the old files to a different location?
Do you want to delete all the files on a list?
Do you have a list of files to be deleted, or a list of files to be kept?

General background...
The FOR command works like this:
  FOR %I  in (a set of files) DO some_command %I

This FOR command takes a file name or several file names contained in the parentheses.
It starts with the first file in that set, reads the name of that file into the variable %I, then does a command of some sort, which can contain the %I to make the command happen to a variable.
When the command has finished, it then get the next file, and does the command again.
It keeps getting the next file and doing the same command until it has gone through all the files in the list.

For example, if you have files A, B C, D, and E, you could enter this:
 FOR %I in (A B E) DO DEL %I

This will delete A, then B, then E, but will not affect C or D.

The set of files can be specified in several different ways. You can just type in a list of files, or you can use a wildcard, like this:
 FOR %I in (*.TMP) DO DEL %I
You can use the /R parameter to tell the FOR command to look not only in the current directory, but also any subdirectories.

FOR /F says that instead of typing in the names in the command, you want it to open up a text file and read the names from there. That's what the example I provided earlier does.

   FOR /F %I in (FileNames.txt) DO COPY %I D:
will read each line from the file FileNames.txt, and COPY each file listed in that file to the D: drive.

%I is a variable. You can just type %I if you're typing the commands at the command prompt directly.
(You could use other letters besides I if you want, like %K, %Z, whtatever.)

In order to use these variables in a batch file, you have to double the percent symbols. So in a batch file, you need to put %%I, not just %I.

You don't HAVE to make a batch file, you can just type the command directly at the command prompt. It's convenient for testing, though.

To create a batch file, just open up NOTEPAD, and type in the commands, then save the file with a .BAT extension.


Author Comment

ID: 16966271

I created a text file called moveme.txt

files include:


I want to move all that are in the moveme.txt file from





Author Comment

ID: 16977354
Looking forward to a solution here.  Thanks.  I think we are close.
LVL 18

Accepted Solution

JoseParrot earned 250 total points
ID: 17006929

Points of attention:
1. The moveme.txt should be in the current directory.
2. If DirectoryA or DirectoryB is a directory name with spaces, enclose it in quotation marks.
    For example,      C:\My Images Folder       type      "C:\My Images Folder"
Then run the command:

FOR /F %n in (moveme.txt) DO MOVE C:\DirectoryA\%n  C:\DirectoryB

Please note billmercer had posted correct instructions.


Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
converting a pms to a cymk 13 25
Flash movie or gif/animation? 3 846
Flash Failing on IE11 and Mozilla 32.0.3 6 405
Animated Gif Templates? 6 180
I've been using this technique since Adobe CS2, and it should work with any version of Illustrator that includes the appearance panel. In this tutorial we'll create a button using the appearance panel in Adobe Illustrator, and then save it as a r…
Many programs have tried to outwit PowerPoint in terms of technology and skill. These programs, however, still lack several characteristics that PowerPoint has possessed from the start. Here's why PowerPoint replacements won't entirely work for desi…
In this Micro Tutorial viewers will learn the basic shortcuts and functions of Illustrator. The viewer will learn about the paintbrush tool, anchor points, font sizing, and more.
In this Micro Tutorial viewers will learn how to remove an unwanted object using Photoshop’s feature known as content-aware fill.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now