anthony_field Posted March 19, 2008 Share Posted March 19, 2008 HEY ALL..I need a Script or Batch file that can do the following ....I have say 100 uniquly named files in one directory named ( lock.dat lock1.dat lock2.dat ) and so on...under c:\lock_files\I need to copy these files to another directory on the same PC c:\lock_upload\What I need is the script/Batch to move on of the 100 unique files at a time to the destination dir \lock_upload\buy move it as a new file name lock.datthen I need the process to wait either a defined time for the next move, or identify if the Lock.dat file exists in the destination dirthen move the next file as lock.dat and so on until all files have been moved as lock.dat to the destination dir.if no files are left to copy just wait until there is then start again. / or exit .. Until I start it manually again.I need it like this, as I have 10000 lines of txt that require uploading into a data base, that scans every one min for the lokc.dat file, as the process takes a long time, I split the files up to process them more quickly, but it is entirly painful moving them manually each time.Please help. Link to comment Share on other sites More sharing options...
Yzöwl Posted March 19, 2008 Share Posted March 19, 2008 If the dat files you are copying or the resultant lock.dat file is binary as opposed to ascii (text), then you could use something like this.@Echo offIf Not Exist C:\lock_files\*.dat Goto :EofIf Not Exist C:\lock_upload Md C:\lock_uploadPushd C:\lock_uploadIf Exist lock.dat (Copy /b lock.dat + C:\lock_files\*.dat &&( Del C:\lock_files\*.dat)) Else (Copy /b C:\lock_files\*.dat lock.dat &&( Del C:\lock_files\*.dat))All you need to do then is schedule the file to run at whatever frequency you require.You will of course need to ensure that none of the files are in use when you run this. Link to comment Share on other sites More sharing options...
anthony_field Posted March 19, 2008 Author Share Posted March 19, 2008 This script works well. Thanks.But it does not have the ability to move only one of the lock files at a time, and wait until it has been processed, then move the next one.It appears to over write the the moved lock.dat file in the destination directory.Can a wait statment be added and if file exists wait until ? Link to comment Share on other sites More sharing options...
Yzöwl Posted March 19, 2008 Share Posted March 19, 2008 Perhaps I misunderstood what you were after.This script appends the content of all files in 'C:\lock_files' with the file extension .dat to a single file named 'C:\lock_upload\lock.dat'Please try to explain your exact requirements fully again! Link to comment Share on other sites More sharing options...
gunsmokingman Posted March 19, 2008 Share Posted March 19, 2008 Try this script just place it in the main folder.It goes threw the folder every 90 seconds, when it has ran 10 times it will ask you to continuue or quit.You have to have this folder C:\lock_upload\ or change StrDestination = "C:\lock_upload\" this tomatch the end location. Const OverWrite = True Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject") On Error Resume Next Dim C1, F1, F2, StrDestination, ZZ1 Set F1 = Fso.GetFolder(".") StrDestination = "C:\lock_upload\" Do For Each F2 In F1.Files If Not F2.Path = WScript.ScriptFullName Then C1 = C1 +1 Fso.CopyFile F2.Path,StrDestination & F2.Name, OverWrite End If If C1 = 10 Then ZZ1 = MsgBox("Did you want to let the script run for 15 minutes more?",4132,"Quit Or Continue") If ZZ1 = 6 Then C1 = 0 If ZZ1 = 7 Then WScript.quit End If '-> Stop The Script For Approx 90 Seconds WScript.Sleep 90000 Next Loop Until C1 = 10 Link to comment Share on other sites More sharing options...
anthony_field Posted March 19, 2008 Author Share Posted March 19, 2008 I will try to be clear this time.. Sorry for the confusion..I have c:\lock_files containing lock.dat lock1.dat lock2.dat ext upto possibly as high as 1000 (sometimes it may only be 100 entries)these files look like P|1879006546|C|First last|3yOR|||||300609|2359P|1879002248|C|First Last|3yOR|||||300609|2359P|1878002250|C|First Last |Ord|||||300608|2359Each person starts on a new line.I do not wish them to append each other on the move.Now I wish to move these file ( one at a time ) as lock.dat to c:\lock_uploadI need the batch to check to see if the destination file exists, if it does wait a desired amount of time then try again and then try again and so on.Until all the files in the c:\lock_files are moved successfully.This Batch file can just loop forever once started.a majority of the time though, the c:\lock_files directory will not contain any files, in this instance it should just wait until there is files to move.Hope this covers it all..I appreciate your assistance. Thanks Link to comment Share on other sites More sharing options...
anthony_field Posted March 19, 2008 Author Share Posted March 19, 2008 Thanks "Gunsmokingman"Athough I can not seem to run this script... have saved it as lockscript.batIt does not seem to run.Any Ideas ?Const OverWrite = TrueDim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")On Error Resume NextDim C1, F1, F2, StrDestination, ZZ1Set F1 = Fso.GetFolder(".") StrDestination = "C:\lock_upload\" Do For Each F2 In F1.Files If Not F2.Path = WScript.ScriptFullName Then C1 = C1 +1 Fso.CopyFile F2.Path,StrDestination & F2.Name, OverWrite End If If C1 = 10 Then ZZ1 = MsgBox("Did you want to let the script run for 15 minutes more?",4132,"Quit Or Continue") If ZZ1 = 6 Then C1 = 0 If ZZ1 = 7 Then WScript.quit End If '-> Stop The Script For Approx 90 Seconds WScript.Sleep 90000 Next Loop Until C1 = 10 Link to comment Share on other sites More sharing options...
Yzöwl Posted March 19, 2008 Share Posted March 19, 2008 It's a VBScript, rename it to lockscript.vbs.By the name `upload` something must be running already processing the lock.dat file, surely that's being done at a regualr interval so that you can do the same with your script. It is not really efficient to keep the script running indefinitely.Here's another attempt at supplying you with a batch solution:MoveDat.cmd@Echo off&SetlocalIf Exist C:\lock_upload\lock.dat Goto :Eoffor /f "delims=" %%# In ('dir/b/o-d/a-d *.dat') Do Set "%F_%=%%#"If Not Defined F_ Goto :EofMove "%F_%" C:\lock_upload\lock.datPlace this script into C:\lock_filesI would suggest you just run this file, (say every five minutes, [300 secs]), using Soon.exe from the Windows® 2000 Resource Kit:soon 300 cmd /c C:\lock_files\MoveDat.cmd Link to comment Share on other sites More sharing options...
anthony_field Posted March 19, 2008 Author Share Posted March 19, 2008 Thats Perfect...Can this VB script Move the file instead of Copy ? Link to comment Share on other sites More sharing options...
anthony_field Posted March 19, 2008 Author Share Posted March 19, 2008 sorry last thing...I need the file to be moved as lock.dat not its original name of lock1.dat and so on...thanks Link to comment Share on other sites More sharing options...
gunsmokingman Posted March 19, 2008 Share Posted March 19, 2008 (edited) Ok I added a check to see if the file is not in the end location Save As WhatEver.vbsConst OverWrite = TrueDim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")On Error Resume NextDim C1, F1, F2, StrDestination, ZZ1Set F1 = Fso.GetFolder(".") StrDestination = "C:\lock_upload\" Do For Each F2 In F1.Files If Not F2.Path = WScript.ScriptFullName Then If Not Fso.FileExists(StrDestination & F2.Name) Then C1 = C1 +1 '-> Uncomment This If You Want To Copy The Original File ' Fso.CopyFile F2.Path,StrDestination & F2.Name, OverWrite '-> This Copies Each File To This Name lock.dat Fso.CopyFile F2.Path,StrDestination & "lock.dat", OverWrite End If End If If C1 = 10 Then ZZ1 = MsgBox("Did you want to let the script run for 15 minutes more?",4132,"Quit Or Continue") If ZZ1 = 6 Then C1 = 0 If ZZ1 = 7 Then WScript.quit End If '-> Stop The Script For Approx 90 Seconds WScript.Sleep 90000 Next Loop Until C1 = 10Since I am not sure what you want I have left a Comment out part of the script that will copy the fileas it original name. It set to copy the file as lock.dat Use this to copy all the files in the parent folder as lock.dat '-> Uncomment This If You Want To Copy The Original File ' Fso.CopyFile F2.Path,StrDestination & F2.Name, OverWrite '-> This Copies Each File To This Name lock.dat Fso.CopyFile F2.Path,StrDestination & "lock.dat", OverWriteUse this to copy the file with it original name '-> Uncomment This If You Want To Copy The Original File Fso.CopyFile F2.Path,StrDestination & F2.Name, OverWrite '-> This Copies Each File To This Name lock.dat ' Fso.CopyFile F2.Path,StrDestination & "lock.dat", OverWriteThis script will overwrite the lock.dat each time it loops threw the collection.So a move file is not needed. Edited March 19, 2008 by gunsmokingman Link to comment Share on other sites More sharing options...
anthony_field Posted March 19, 2008 Author Share Posted March 19, 2008 (edited) I actually need the copied / moved lock.dat to be processed by the server, it then disapears.then the next file can be moved.I need the Files that are waiting to be copied/moved to be deleted once successfullyIt also seems to move the .vbs script into the _upload folder, when infact I need it to remain in it original folder.Many Thanks for your help...Got it..."Const OverWrite = TrueDim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")On Error Resume NextDim C1, F1, F2, StrDestination, ZZ1Set F1 = Fso.GetFolder(".") StrDestination = "C:\lock_move\" Do For Each F2 In F1.Files If Not F2.Path = WScript.ScriptFullName Then If Not Fso.FileExists(StrDestination & "lock.dat") Then C1 = C1 +1 '-> This Copies Each File To This Name lock.dat Fso.CopyFile F2.Path,StrDestination & "lock.dat", OverWrite F2.Delete End If End If If C1 = 10 Then ZZ1 = MsgBox("Did you want to let the script run for 15 minutes more?",4132,"Quit Or Continue") If ZZ1 = 6 Then C1 = 0 If ZZ1 = 7 Then WScript.quit End If '-> Stop The Script For Approx 90 Seconds WScript.Sleep 10000 Next Loop Until C1 = 10"Works Great Edited March 20, 2008 by anthony_field Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now