finnstone
asked on
DELETE IMAGES IN A FOLDER ACCORDING TO A LIST OF FILE NAMES
i have a list in col A of excel of files names. the file names are purely numbers, so maybe that makes it easier.
need to look in windows folder for those file names and delete files if they match the list.
need to look in windows folder for those file names and delete files if they match the list.
Do the cells contain just the name or do they include the file extension e.g .jpg?
ASKER
Hi Bill, sounds like the answer I need, but can you explain more?
Another approach would be to save the list from column A to a text file, let's say list.txt. Then use a small BAT file as shown below to read that text file and delete the files specified from the specified base folder. Save below as a .BAT file, adjust the BaseDir variable, place the list.txt file in the same folder, open a DOS command prompt and execute the named .BAT file.
»bp
@echo off
setlocal
set BaseDir=c:\temp
set ListFile=list.txt
for /f "usebackq tokens=*" %%A in ("%ListFile%") do (
if exist "%BaseDir%\%%~A" del "%BaseDir%\%%~A"
)
»bp
Are they all in the same folder?
ASKER
yes norie
Hi Bill, sounds like the answer I need, but can you explain more?
- Place that formula into B1 adjust the path from c:\temp to be your folder.
- Copy the formula down column B as far as the file names go in column A.
- Select all of column B and copy it.
- Open Notepad (or other text editor) and past the column B DEL statements there.
- Save as a .BAT file with a non common name, let's say EE29106674.BAT.
- Open Command Prompt from Start menu.
- Do a CD command to the folder where you saved EE29106674.BAT.
- At the prompt type EE29106674.BAT and press return.
- It should run each DEL statement and delete the file if it exists.
»bp
If your files have a common extension like .JPG then adjust the formula as:
=CONCATENATE("del ""c:\temp\", A1,".jpg""")
»bp
=CONCATENATE("del ""c:\temp\", A1,".jpg""")
»bp
ASKER
for this approach, do i need to specify extension in list.txt?
Another approach would be to save the list from column A to a text file, let's say list.txt. Then use a small BAT file as shown below to read that text file and delete the files specified from the specified base folder. Save below as a .BAT file, adjust the BaseDir variable, place the list.txt file in the same folder, open a DOS command prompt and execute the named .BAT file.
Another approach would be to save the list from column A to a text file, let's say list.txt. Then use a small BAT file as shown below to read that text file and delete the files specified from the specified base folder. Save below as a .BAT file, adjust the BaseDir variable, place the list.txt file in the same folder, open a DOS command prompt and execute the named .BAT file.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
what is command in msdos to execute bat file?
ASKER
it worked. wow!
ASKER
awesome
Great, glad that was useful.
»bp
»bp
=CONCATENATE("del ""c:\temp\", A1,"""")
»bp