Computer Hope

Microsoft => Microsoft DOS => Topic started by: silberzin on July 13, 2010, 06:40:06 AM

Title: files listed added to folder during last week
Post by: silberzin on July 13, 2010, 06:40:06 AM
Hi All

I have rather very difficult task to accomplish. Can you help me and prepare script as *.bat. That script should check folder (it will be network path) and list all files created within last week in that folder. Next to file name should be creation date.
Script should list results on screen and also create txt fog file each time script is running.

Is possible to create such script?
Unfortunatelly my programming skills are not so big therefore if possible please advice in more details :)

Thank you in advance.

BR
Michal
Title: Re: files listed added to folder during last week
Post by: gpl on July 13, 2010, 07:37:28 AM
Will this do ?
Code: [Select]
@echo off

REM create the vb script
>evaluate.vbs echo Wscript.echo eval(WScript.Arguments(0))

REM extract todays date less 7 days
for /f "delims=" %%A in ( ' cscript //nologo evaluate.vbs "Date -7" ' ) do set OldestDate = %%A

REM tidy
del evaluate.vbs

REM break up the date into constituent parts
REM Note - the date is parsing UK format dates,
REM        swap the MM and DD in the lines below
REM        for US format

set MM=%OldestDate:~3,2%
set DD=%OldestDate:~0,2%
set YYYY=%OldestDate:~6,4%

REM reconstruct US format with '-' separators
set OldestDate=%MM%-%DD%-%YYYY%

REM list the files that would be copied if we really were doing a copy
REM force it to believe that the target NonExistentDirectory is a directory
REM and echo the name & time for each

for /f "delims=" %%A in ( ' xcopy /l /i /d:%OldestDate% *.*  NonExistentDirectory ' ) do echo %%A %%~tA

I assume you meant to say 'logfile each time the script runs' ... what would go in there ? the date and time the script ran ?
Title: Re: files listed added to folder during last week
Post by: silberzin on July 13, 2010, 11:44:35 PM
Hi

Thank you for replay.

Basically what we need  is script which we will add to scheduled tasks in windows.
When script finish we should have results displayed on the screen (for example in cmd) and log file when script was run (date is enough but if is possible also time)



How should save that file as *.bat or *.vbs?

I do not need  copy files, just list the newest from last week with creation date.
My time zone is Europe (DK), maybe some part of the script has to be changed.

I am sorry if I am asking not to smart questions :)
Thank you very much.

BR
Michal
Title: Re: files listed added to folder during last week
Post by: gpl on July 14, 2010, 12:42:06 AM
Hi Michal
No, you are asking very good questions!

You would save it with a .bat extension, the small vbscript that is used is created by the batch, this is because date and time manipulation is simple in vbscript but nearly impossible in batch files

The XCopy is not actually copying anything - but listing the files that would be copied; the /L tells it not to copy anything

If you schedule this then you will not see any output, I suggest that the list of files is placed in the log also.

Denmark uses the correct date format  ;D so that you will not need to change the script

This is the latest version, you will need to change the drive and directory in line 2 to be the folder that you wish to monitor
In Line 3, a variable is created to hold the location of your logfile, you will have to change this also to be the name and location of your log
Code: [Select]
@echo off
CD /d F:\FolderForFiles
Set LogFile="d:\logs\NewFiles.Log"

REM create the vb script
>evaluate.vbs echo Wscript.echo eval(WScript.Arguments(0))

REM extract todays date less 7 days
for /f "delims=" %%A in ( ' cscript //nologo evaluate.vbs "Date -7" ' ) do set OldestDate = %%A

REM tidy
del evaluate.vbs

REM break up the date into constituent parts
REM Note - the date is parsing UK format dates,
REM        swap the MM and DD in the lines below
REM        for US format

set MM=%OldestDate:~3,2%
set DD=%OldestDate:~0,2%
set YYYY=%OldestDate:~6,4%

REM reconstruct US format with '-' separators
set OldestDate=%MM%-%DD%-%YYYY%

REM add the new entry to the log
>> %LogFile% Echo %DATE% %TIME%
REM list the files that would be copied if we really were doing a copy
REM force it to believe that the target NonExistentDirectory is a directory
REM and echo the name & time for each

for /f "delims=" %%A in ( ' xcopy /l /i /d:%OldestDate% *.*  NonExistentDirectory ' ) do call :ProcessEach %%A

REM tidy up the log
>> %LogFile% Echo ========================================

goto :EOF

:ProcessEach

>> %LogFile% echo %%~fA %%~tA

goto :EOF
One problem with this is that the last line of each log entry will say xxx File(s) Copied, with the path preceding it
Title: Re: files listed added to folder during last week
Post by: silberzin on July 14, 2010, 01:25:01 AM
Hi gpl

Thank you very much for your help. The script is working almost :) I just got information: "Invalid number of parameters"

I do not know why. only what I did was change folder location:
@echo off
CD /d e:\pictures
Set LogFile="e:\NewFiles.Log"

Can we have separate log for each day? then we can track changes for each day. It is complicated to explain why ( read -> bos) :)

Thank you very very much for help :)

BR
Michal
Title: Re: files listed added to folder during last week
Post by: gpl on July 14, 2010, 01:54:34 AM
Hi Michal
It is hard to tell what the problem is, change the first line to @Echo On and you will see how each command is made up after variables have been expanded

Yes you can have a new file every day, remember the section that creates a variable with the date of 1 week ago, we can do domething similar:

Code: [Select]
@echo off
CD /d e:\pictures

REM grab todays date into variables
set MM=%Date:~3,2%
set DD=%Date:~0,2%
set YYYY=%Date:~6,4%

REM Add the date variables to the log name
REM putting the date in this order will sort the files sensibly
Set LogFile="e:\NewFiles_%YYYY%-%MM%-%DD%.Log"

REM create the vb script
>evaluate.vbs echo Wscript.echo eval(WScript.Arguments(0))

REM extract todays date less 7 days
for /f "delims=" %%A in ( ' cscript //nologo evaluate.vbs "Date -7" ' ) do set OldestDate = %%A

REM tidy
del evaluate.vbs

REM break up the date into constituent parts
REM Note - the date is parsing UK format dates,
REM        swap the MM and DD in the lines below
REM        for US format

set MM=%OldestDate:~3,2%
set DD=%OldestDate:~0,2%
set YYYY=%OldestDate:~6,4%

REM reconstruct US format with '-' separators
set OldestDate=%MM%-%DD%-%YYYY%

REM add the new entry to the log
>> %LogFile% Echo %DATE% %TIME%
REM list the files that would be copied if we really were doing a copy
REM force it to believe that the target NonExistentDirectory is a directory
REM and echo the name & time for each

for /f "delims=" %%A in ( ' xcopy /l /i /d:%OldestDate% *.*  NonExistentDirectory ' ) do call :ProcessEach %%A

REM tidy up the log
>> %LogFile% Echo ========================================

goto :EOF

:ProcessEach

>> %LogFile% echo %%~fA %%~tA

goto :EOF


I suspect the error about the invalid number of parameters is because you have a file or directory name somewhere with a space in it and the name is not enclosed by quotes - with echo on, it will be clear where.

Graham
Title: Re: files listed added to folder during last week
Post by: silberzin on July 14, 2010, 04:26:14 AM
Hi gpl

I jsut make as suggested, here is error information:
E:\Pictures>for /F "delims=" %A in (' xcopy /l /i /d:~3 2-~0 2-~6 4 *.* NonExist
entDirectory ') do call :ProcessEach %A
Invalid number of parameters

Do you know how to fix that?

BTW:
error log: excellent job :)

Thank you in advance for help.

BR
Michal
Title: Re: files listed added to folder during last week
Post by: gpl on July 14, 2010, 05:14:22 AM
It is clear why the error comes up, the %oldestdate% variable no longer holds a date

you will note that the xcopy instruction looks like this before expansion
xcopy /l /i /d:%OldestDate%
but what you see expanded is
xcopy /l /i /d:~3 2-~0 2-~6 4

I think you may have deleted a % or more in these lines
Code: [Select]
set MM=%OldestDate:~3,2%
set DD=%OldestDate:~0,2%
set YYYY=%OldestDate:~6,4%

REM reconstruct US format with '-' separators
set OldestDate=%MM%-%DD%-%YYYY%

Graham
Title: Re: files listed added to folder during last week
Post by: silberzin on July 14, 2010, 05:31:23 AM
Hi Graham

I just tried to add more, but I can't make it work.

Can you try how it works on your computer, and publish the code. I make some mistake (s) - my programming skills are not so great therefore I do not trust my self :)

maybe something to do is also about date, I noticed that log file has this date format:
NewFiles_7-14-0--20.Log which is almost correct :)


Thank you in advance.

BR
Michal
Title: Re: files listed added to folder during last week
Post by: gpl on July 14, 2010, 05:51:30 AM
OK Michal
The last change I did to make the logfile name hold todays date stopped it working.

In the version below, I have blanked the OldestDate, DD, MM and YYYY variables before they are reused and it is working again .... except the bit that shows the name and creation time didnt work either - that is now fixed.

Try this
Code: [Select]
@echo off
CD /d e:\pictures

REM grab todays date into variables
set MM=%Date:~3,2%
set DD=%Date:~0,2%
set YYYY=%Date:~6,4%

REM Add the date variables to the log name
REM putting the date in this order will sort the files sensibly
Set LogFile="e:\NewFiles_%YYYY%-%MM%-%DD%.Log"

REM create the vb script
>evaluate.vbs echo Wscript.echo eval(WScript.Arguments(0))

REM extract todays date less 7 days
set OldestDate=
for /f "delims=" %%A in ( ' cscript //nologo evaluate.vbs "Date -7" ' ) do set OldestDate=%%A

REM tidy
del evaluate.vbs

REM break up the date into constituent parts
REM Note - the date is parsing UK format dates,
REM        swap the MM and DD in the lines below
REM        for US format

set MM=
set DD=
set YYYY=

set MM=%OldestDate:~3,2%
set DD=%OldestDate:~0,2%
set YYYY=%OldestDate:~6,4%

REM reconstruct US format with '-' separators
set OldestDate=%MM%-%DD%-%YYYY%

REM add the new entry to the log
>> %LogFile% Echo %DATE% %TIME%
REM list the files that would be copied if we really were doing a copy
REM force it to believe that the target NonExistentDirectory is a directory
REM and echo the name & time for each

for /f "delims=" %%A in ( ' xcopy /l /i /d:%OldestDate% *.*  NonExistentDirectory ' ) do call :ProcessEach %%A

REM tidy up the log
>> %LogFile% Echo ========================================

goto :EOF

:ProcessEach

>> %LogFile% echo %~f1 %~t1

goto :EOF
Graham
Title: Re: files listed added to folder during last week
Post by: silberzin on July 14, 2010, 05:59:12 AM
hi Graham

It seems to be working now. No error :)

But :))))

in the log message there is no new files listed only date like that (I think date when script was running - your correction):

2010-07-14 13:55:08,37
========================================
2010-07-14 13:55:14,53
========================================
2010-07-14 13:55:26,75
========================================


I created few files today, but they are not listed. Any change to list them together with creation date?

Thank you very much for help.

I very much appreciate your fast help.

BR
Michal
Title: Re: files listed added to folder during last week
Post by: gpl on July 14, 2010, 06:24:23 AM
I think I have it
The entry in your log is
2010-07-14 13:55:26,75
I think that this is the default way a date is shown on your computer; the section that calculates the date 7 days before is not quite right; I think that you should try this instead
Code: [Select]
@echo off
CD /d e:\pictures

REM grab todays date into variables
set MM=%Date:~3,2%
set DD=%Date:~0,2%
set YYYY=%Date:~6,4%

REM Add the date variables to the log name
REM putting the date in this order will sort the files sensibly
Set LogFile="e:\NewFiles_%YYYY%-%MM%-%DD%.Log"

REM create the vb script
>evaluate.vbs echo Wscript.echo eval(WScript.Arguments(0))

REM extract todays date less 7 days
set OldestDate=
for /f "delims=" %%A in ( ' cscript //nologo evaluate.vbs "Date -7" ' ) do set OldestDate=%%A

REM tidy
del evaluate.vbs

REM break up the date into constituent parts
REM Note - the date is parsing YYYY-MM-DD format dates,

set MM=
set DD=
set YYYY=

set MM=%OldestDate:~5,2%
set DD=%OldestDate:~8,2%
set YYYY=%OldestDate:~0,4%

REM reconstruct US format with '-' separators
set OldestDate=%MM%-%DD%-%YYYY%

REM add the new entry to the log
>> %LogFile% Echo %DATE% %TIME%
>> %LogFile% Echo Since : %OldestDate%
REM list the files that would be copied if we really were doing a copy
REM force it to believe that the target NonExistentDirectory is a directory
REM and echo the name & time for each

for /f "delims=" %%A in ( ' xcopy /l /i /d:%OldestDate% *.*  NonExistentDirectory ' ) do call :ProcessEach %%A

REM tidy up the log
>> %LogFile% Echo ========================================

goto :EOF

:ProcessEach

>> %LogFile% echo %~f1 %~t1

goto :EOF


Ive added a line which inserts into the log
Since : 'the value of OLDESTDATE'
which is in US format
Could you try it ?
Thanks
Graham
Title: Re: files listed added to folder during last week
Post by: silberzin on July 14, 2010, 06:55:40 AM
Hi Graham

It seems to be working a lot better now. It is creating log with information like that:

2010-07-14 14:42:31,45
Since : 07-07-2010
E:\all
E:\New
E:\NewFiles_7-14-0--20.Log 2010-07-14 14:42
E:\test.xml 2010-07-14 14:41
E:\4
========================================


the only small problem is that file names are not complet (I marked 2 names as blue as example).

2010-07-14 14:42:31,45
Since : 07-07-2010
E:\all Briefcase.bfc
E:\New all files for last 7 days.bat
E:\NewFiles_7-14-0--20.Log 2010-07-14 14:42
E:\test.xml 2010-07-14 14:41
E:\4
========================================


The other is I do not have file 4, and I do not know from ´where it come from.

To easier read log is possible to have file file name few "spaces" and then date?
example:
E:\test.xml                                           2010-07-14 14:41

One more question, I tried to change path to network path as we are going to monitor network folders, but the script is constantly show report for "old" my local path (that same result after deleting path). Do you know how to fix that?

In the future I will be monitoring few network folders, by simply copy/paste this code in that some file and change monitoring folder path (log will stay that some).

like this:

code
----------------

@echo off
CD /d \\server\path1

REM grab todays date into variables
.
.
.
goto :EOF

CD /d \\server\path2

REM grab todays date into variables
.
.
.
goto :EOF


BR
Michal
Title: Re: files listed added to folder during last week
Post by: gpl on July 14, 2010, 08:09:50 AM
Hi Michal
The 4 is simply the number of files found (it should actually read 4 File(s) copied)
the batch file which you highlighted is locked as it is executing, I expect that is why it does not show the timestamp, maybe that is why the 'all Briefcase.bfc' file does not show a date either

the line near the bottom is the one that writes the info to the log
Code: [Select]
>> %LogFile% echo %~f1 %~t1
change to this
Code: [Select]
[code]>> %LogFile% echo %~f1                                     %~t1or even use tab characters instead of spaces

I am not very sure how to user the \\servername - batch files dont like it and try to change to a d: type drive
You could try remapping the servers to drive e: and running the batch ?

Otherwise, perhaps one of the more experienced members here could jump in with the solution ?

Graham[/code]
Title: Re: files listed added to folder during last week
Post by: silberzin on July 14, 2010, 11:53:37 PM
Hi Graham

Thank you for info with log it works fine.

I just checked. Whenever I use one of mounted diskson my computer like c: or e: then I can see the list.
However when I use \\servername\network path it is not working.
Conclusion is that application works on mapped disks but not on network.

Regarding 'all Briefcase.bfc' the name have space. That is the problem. With no space I can see all as expected :)
Luckily that is not a problem because all files I have to monitor insted of space have "_".


It is very important for me that application can work with network path as I am going to monitor many folders (probably I do not have enough letters to map all the disks :)
Please help  :'(

Do you or anybody know how to fix that?

Thank you for any help.

BR
Michal

Title: Re: files listed added to folder during last week
Post by: gpl on July 15, 2010, 12:31:23 AM
Michal
Ah - spaces in names always trip me up

in this line, put quotes around the %%A
Code: [Select]
for /f "delims=" %%A in ( ' xcopy /l /i /d:%OldestDate% *.*  NonExistentDirectory ' ) do call :ProcessEach "%%A"
That should cure the problem

I did not mean for you to map all of your paths to different letters, I was thinking of using 1 letter and each server path being mapped in turn to it

However if anyone else has a more elegant solution, please post here
Graham
Title: Re: files listed added to folder during last week
Post by: silberzin on July 15, 2010, 03:13:24 AM
Hi Graham

Yes it works perfect now, all names are displayed.

The only problem is scanning network path. Local path are wotking perfect.

I just checked.
1) when I have disk p: - all works
but
2) when I use \\server_name\folder (his some path as mapped in case 1) to p:) - then script is listening files from disk where script is placed instead of network path.

I think after changing command
cd /d e:
to
dir \p \\server name\folder

it is also listing files from disk on which script was running.



I just checked by adding pause here:

Code: [Select]
>> %LogFile% echo End of LOG

pause
goto :EOF

:ProcessEach

on CMD command I can see it is listing my network files so it see link and files listed are correct form link \\server name\folder
Just entries send to  the log are not correct and come from drive where script was running.




If that can help... maybe you can have any idea :)

BR
Michal


Title: Re: files listed added to folder during last week
Post by: gpl on July 15, 2010, 04:30:52 AM
Michal
change the line
cd /d e:
to
cd /d p:\

then do this (assuming e:\batchfile.bat is where you have saved the batchfile)
Code: [Select]
net use p: /delete

net use p: \\computer name1\share name
call e:\batchfile.bat
net use p: /delete

net use p: \\computer name2\share name
call e:\batchfile.bat
net use p: /delete

net use p: \\computer name3\share name
call e:\batchfile.bat
net use p: /delete

I have added a line that should display the servername in the log too, in this line
Code: [Select]
net use p:|find "Remote name">> %LogFile%
This should be the complete script
Code: [Select]
@echo off
CD /d p:\

REM grab todays date into variables
set MM=%Date:~3,2%
set DD=%Date:~0,2%
set YYYY=%Date:~6,4%

REM Add the date variables to the log name
REM putting the date in this order will sort the files sensibly
Set LogFile="e:\NewFiles_%YYYY%-%MM%-%DD%.Log"

REM create the vb script
>evaluate.vbs echo Wscript.echo eval(WScript.Arguments(0))

REM extract todays date less 7 days
set OldestDate=
for /f "delims=" %%A in ( ' cscript //nologo evaluate.vbs "Date -7" ' ) do set OldestDate=%%A

REM tidy
del evaluate.vbs

REM break up the date into constituent parts
REM Note - the date is parsing YYYY-MM-DD format dates,

set MM=
set DD=
set YYYY=

set MM=%OldestDate:~5,2%
set DD=%OldestDate:~8,2%
set YYYY=%OldestDate:~0,4%

REM reconstruct US format with '-' separators
set OldestDate=%MM%-%DD%-%YYYY%

REM add the new entry to the log
>> %LogFile% Echo %DATE% %TIME%
>> %LogFile% Echo Since : %OldestDate%
net use p:|find "Remote name">> %LogFile%

REM list the files that would be copied if we really were doing a copy
REM force it to believe that the target NonExistentDirectory is a directory
REM and echo the name & time for each

for /f "delims=" %%A in ( ' xcopy /l /i /d:%OldestDate% *.*  NonExistentDirectory ' ) do call :ProcessEach "%%A"

REM tidy up the log
>> %LogFile% Echo ========================================

goto :EOF

:ProcessEach

>> %LogFile% echo %~f1                       %~t1

goto :EOF
Title: Re: files listed added to folder during last week
Post by: silberzin on July 15, 2010, 05:13:20 AM
Hi gpl

Thank you for your replay :)

Now is almost working :)

I got that error.

Code: [Select]
E:\>call e:\batchfile.bat
Access is denied.
Could Not Find P:\evaluate.vbs
The network connection could not be found.

More help is available by typing NET HELPMSG 2250.

Invalid number of parameters
There are open files and/or incomplete directory searches pending on the connect
ion to p:.

I think that is because connecting and disconnecting drive. I triet to change
Code: [Select]
Could Not Find P:\evaluate.vbs it on c:
but it keep the same.

Do you know how to fix that "tini tany problem ".

Thank you ion advance :)

last think:
Do you kno if is possible that system will not be asking:
Code: [Select]
Is it OK to continue disconnecting and force them closed? (Y/N) [N]:it may be rather annoying when we will start this task for 20 or 30 folders :)

br
Michal
Title: Re: files listed added to folder during last week
Post by: gpl on July 15, 2010, 06:13:58 AM
Hi Michal
I think we can get around the problem of the vbscript, make the changes I have coloured red
REM create the vb script
>e:\evaluate.vbs echo Wscript.echo eval(WScript.Arguments(0))

REM extract todays date less 7 days
set OldestDate=
for /f "delims=" %%A in ( ' cscript //nologo e:\evaluate.vbs "Date -7" ' ) do set OldestDate=%%A


and then

REM tidy
del e:\evaluate.vbs


I do not know any more about the net use command, had to look up the syntax and it doesnt appear to have an 'always yes' parameter - there is a trick that forces a response into a command, which may work
Code: [Select]
echo Y|net use p: /delete
The source I looked up suggested that the mapping be done like this:
Code: [Select]
START /wait NET USE [driveletter:] \\ComputerName\ShareNameas it will ensure the mapping is complete before attempting to do anything with the drive

I hope this sorts out everything, if not then someone with more expertise will have to help as Im fairly lost with network things
Graham
Title: Re: files listed added to folder during last week
Post by: silberzin on July 15, 2010, 06:42:38 AM
Hi Graham :)

I made changes,
I think it look better now :)

I add /yes to delete command, now is no problem with disconnecting diks:)

Code: [Select]
echo Y|net use p: /delete /yes


BR
Michal
Title: Re: files listed added to folder during last week
Post by: silberzin on July 15, 2010, 07:04:36 AM
Hi Graham

I think script is almost perfect now :)

I have that message:

Code: [Select]

E:\>call e:\batchfile.bat
The option / is unknown.

The syntax of this command is:


NET USE
[devicename | *] [\\computername\sharename[\volume] [password | *]]
        [/USER:[domainname\]username]
        [/USER:[dotted domain name\]username]
        [/USER:[username@dotted domain name]
        [/SMARTCARD]
        [/SAVECRED]
        [[/DELETE] | [/PERSISTENT:{YES | NO}]]

NET USE {devicename | *} [password | *] /HOME

NET USE [/PERSISTENT:{YES | NO}]


More help is available by typing NET HELPMSG 3506.

Press any key to continue . . .

when I use swith "pause"

I do not know if that can generate potential problems.
Until not script seems to be working :)
Title: Re: files listed added to folder during last week
Post by: gpl on July 15, 2010, 07:20:39 AM
I think you should remove the /yes from the net use p: /delete command

If you are remapping the P drive and calling the batch script, it should be working....
are you doing the start wait net use ..... command, this should make sure the drive is ready before you try to access it.

if you look in the log, does it record all of the servers ? or the same one multiple times ?

Graham
Title: Re: files listed added to folder during last week
Post by: silberzin on July 15, 2010, 07:29:55 AM
Hi Graham

Unfortunatelly I tested and files listed are correct. But all come from first server, it is not looking into second file location.

2010-07-15 15:26:31,29
Since : 07-08-2010
Remote name      \\server1\folder
P:\2010070800                      2010-07-08 02:34
P:\20100712                       2010-07-12 02:39
P:\2010071                      2010-07-12 02:39

P:\24 File(s)                       
========================================
2010-07-15 15:26:32,91
Since : 07-08-2010
Remote name      \\server1\folder
P:\2010070800                      2010-07-08 02:34
P:\20100712                       2010-07-12 02:39
P:\2010071                      2010-07-12 02:39

P:\24 File(s)                       
========================================
2010-07-15 15:26:34,10
Since : 07-08-2010
Remote name      \\server1\folder
P:\2010070800                      2010-07-08 02:34
P:\20100712                       2010-07-12 02:39
P:\2010071                      2010-07-12 02:39

P:\24 File(s)                       
========================================
Title: Re: files listed added to folder during last week
Post by: gpl on July 15, 2010, 07:45:47 AM
Hi
Could you post what you have that maps the servers and calls the batch - there might be something there
Thanks
Graham
Title: Re: files listed added to folder during last week
Post by: silberzin on July 15, 2010, 08:28:32 AM

Hi Graham

Here is simple batch I got from you:
Code: [Select]
echo Y|net use p: /delete

START /wait NET USE p: \\server1\MDPRD\distributions\Inbound\70\70_Customer_flat\Archive
call e:\batchfile.bat
echo Y|net use p: /delete

echo Y|net use p: /delete
START /wait NET USE p: \\server1\MDPRD\distributions\P31\BW__RACUGRP\Archive
call e:\batchfile.bat
echo Y|net use p: /delete

START /wait NET USE p: \\server1\MDPRD\distributions\Archive
call e:\batchfile.bat
echo Y|net use p: /delete

This one I start checking folders.

BR
Michal
Title: Re: files listed added to folder during last week
Post by: gpl on July 15, 2010, 10:14:43 AM
Michal
Sorry for the delay, but work got in the way

Is your server really called server1 ?
I am thinking that it is not disconnecting before the next assignment.
Put the line
Code: [Select]
@echo Y|net use p: /deletein a file called e:\disconnect_P.bat
then replace the
Code: [Select]
echo Y|net use p: /delete lines with
Code: [Select]
START /wait e:\disconnect_P.batThis may allow it to complete :
Code: [Select]
START /wait e:\disconnect_P.bat

START /wait NET USE p: \\server1\MDPRD\distributions\Inbound\70\70_Customer_flat\Archive
call e:\batchfile.bat
START /wait e:\disconnect_P.bat

START /wait NET USE p: \\server1\MDPRD\distributions\P31\BW__RACUGRP\Archive
call e:\batchfile.bat
START /wait e:\disconnect_P.bat

START /wait NET USE p: \\server1\MDPRD\distributions\Archive
call e:\batchfile.bat
START /wait e:\disconnect_P.bat
Good luck
Graham
Title: Re: files listed added to folder during last week
Post by: silberzin on July 16, 2010, 12:01:37 AM
Hi Graham

I also think there is some disconnecting problem. I just cehcked and last (in all cases first folder stay mapped after script is finished.)
That suggest your suspiction is right.

I just changed in your script from p: disk which I use to non existing one (y:) system is promting that no disc found in one cmd, on another asking if disconnect. I answer Y but nothing happen.

When in batch file called: disconnect.bat I add
Code: [Select]
@echo Y|net use p: /delete
exit
then something happened. But still only connecting to first disk and not going to another  :'(


I have a filling that your solution is very close :)

BR
Michal
Title: Re: files listed added to folder during last week
Post by: silberzin on July 16, 2010, 02:44:42 AM
Hi Graham

Just for tests I make that code:

Code: [Select]
echo Y|net use y: /delete

START /wait NET USE y: \\server1\MDPRD\distributions\Inbound\70\70_Customer_flat\Archive
call e:\batchfile.bat

echo Y|net use y: /delete

pause
echo Y|net use y: /delete


START /wait NET USE y: \\server1\MDPRD\distributions\P31\BW__RACUGRP\Archive

call e:\batchfile.bat
echo Y|net use y: /delete

here is result from cmd:



E:\>echo Y  | net use y: /delete
y: was deleted successfully.


Quote


E:\>echo Y  | net use y: /delete
y: was deleted successfully.

E:\>START /wait NET USE y: \\server1\MDPRD\distributions\Inbound\70\70_Customer_flat\Archive


E:\>call e:\batchfile.bat
The device is being accessed by an active process. <---- here net use delete  is failing

More help is available by typing NET HELPMSG 2404.

Press any key to continue . .


it has something to do with deleting network drive y: (I hanged it some time from p: to y: as I wanted to test on non used drive)

BR
Michal