Jump to content

Recommended Posts

:thumbup

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

then 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 dir

then 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


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 off
If Not Exist C:\lock_files\*.dat Goto :Eof
If Not Exist C:\lock_upload Md C:\lock_upload
Pushd C:\lock_upload
If 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

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

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

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 to

match 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

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

P|1879002248|C|First Last|3yOR|||||300609|2359

P|1878002250|C|First Last |Ord|||||300608|2359

Each 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_upload

I 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

Thanks "Gunsmokingman"

Athough I can not seem to run this script...

have saved it as lockscript.bat

It does not seem to run.

Any Ideas ?

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

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&Setlocal
If Exist C:\lock_upload\lock.dat Goto :Eof
for /f "delims=" %%# In ('dir/b/o-d/a-d *.dat') Do Set "%F_%=%%#"
If Not Defined F_ Goto :Eof
Move "%F_%" C:\lock_upload\lock.dat

Place this script into C:\lock_files

I 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

Ok I added a check to see if the file is not in the end location

Save As WhatEver.vbs

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
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 = 10

Since I am not sure what you want I have left a Comment out part of the script that will copy the file

as 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", OverWrite

Use 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", OverWrite

This script will overwrite the lock.dat each time it loops threw the collection.

So a move file is not needed.

Edited by gunsmokingman
Link to comment
Share on other sites

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 successfully

It 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 = 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_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 by anthony_field
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...