1.

Solve : need a batch file to move files depending on a condition?

Answer»

i have a list of filenames with me. now i want to move that list of files to another folder using a batch script..

i need this to be done for a clean up activity

can ANYONE help me out?The FOR command strikes again!!

If you are just moving a list, it is pretty simple. Make sure you type out your list of file names in a plain text file (.txt) and be sure they all have the appropriate extensions to them:

<>
1file.pdf
2file.pptx
3file.docx
...

Then set up a for command to process the files:

Code: [Select]@echo off
setlocal enabledelayedexpansion
set old=c:\oldfilepath
set new=c:\newfilepath

for /f "delims=" %%G in (List.txt) do copy %old%\%%G %new%\%%Gthankyou very much. this helps me lot

but i need to CHECK a condition on file NAME.. this script i want to run on 300 gb data and i want to check the file names starting
with the ids retrieved by the database.

so do you have any idea for this?Quote from: srujana on October 03, 2011, 04:05:19 AM

but i need to check a condition on file name.. this script i want to run on 300 gb data and i want to check the file names starting
with the ids retrieved by the database.

I'm going to do my best to answer the question that I think you are asking here. First, there is a database that you have that has certain IDs in it. Second, you want to move only the files that match an ID in that database. And third (and irrelevant in this situation), you are running this program on 300 GB of data.

Given that all of the above is true, here is how I WOULD solve the problem:

First, OUTPUT the IDs from the database to a plain text file.

<>
ID1
ID2
ID3
etc...

Then use this:

Code: [Select]@echo off
setlocal enabledelayedexpansion
set old=c:\oldfilepath
set new=c:\newfilepath

for /f "delims=" %%G in (output.txt) do (
for /f "delims=" %%H in ('dir %old% "%%G" /s /b') do copy %old%\%%H %new%\%%H
)

It's late here so please identify any errors you run into as I have not taken the time to test this.use the below

move \*.*
ex: move C:\test\*.* C:\test\bak

The problem with move is that it automatically deletes the file from the original location. Copy is safer because if the copy doesn't complete correctly, the file still exists. Once the OP is satisfied that all files are in the new location, all they would need to do is change the code from
Code: [Select]for /f "delims=" %%H in ('dir %old% "%%G" /s /b') do copy %old%\%%H %new%\%%Hto
Code: [Select]for /f "delims=" %%H in ('dir %old% "%%G" /s /b') do del %old%\%%Hand run it again.


Discussion

No Comment Found