| 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.. 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 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. |
|