thesurg3on
asked on
VBScript: Map Network Drive, Run Command, Disconnect Network Drive
Hi,
I am hoping to get some help on a script that does the following:
map a network drive to a UNC path
run a command: forfiles /p "z:\" /m *.txt /d -365 /c "cmd del /q @file"
disconnect the network drive from the UNC path
I am hoping to get some help on a script that does the following:
map a network drive to a UNC path
run a command: forfiles /p "z:\" /m *.txt /d -365 /c "cmd del /q @file"
disconnect the network drive from the UNC path
ASKER
i didnt use your vestion with the &chr(34) &, nevertheless, it seems like the same results. the network drive runs, but the forfiles never runs.
Set objNet = CreateObject("Wscript.netw ork")
Set objShell = CreateObject("Wscript.Shel l")
'objNet.MapNetworkDrive "Z:","\\server\path",True
objShell.Run "forfiles /p ""z:\"" /m *.done /d -365 /c ""cmd del /q @file"""
'objNet.RemoveNetworkDrive "Z:",True,True
Set objNet = CreateObject("Wscript.netw
Set objShell = CreateObject("Wscript.Shel
'objNet.MapNetworkDrive "Z:","\\server\path",True
objShell.Run "forfiles /p ""z:\"" /m *.done /d -365 /c ""cmd del /q @file"""
'objNet.RemoveNetworkDrive
ASKER
all the forfiles is supposed to do is delete any file older than 365 days with the extension .done
you have to use the version with the chr(34) option as vbscript else cannot handle the quotes. Please use my original version and try again
ASKER
i did use your version and it did not work
what is chr(34)? is it a single quote or a double quote? my initial question shows the quotes exactly as if you were to run it from the command line. I thought you had to escape a quote out with preceding quote, which is why i removed yoru chr(34) and put in a " instead.
what is chr(34)? is it a single quote or a double quote? my initial question shows the quotes exactly as if you were to run it from the command line. I thought you had to escape a quote out with preceding quote, which is why i removed yoru chr(34) and put in a " instead.
because vbscript will interpret them and your command line will be destroyed.
Chr(34) is a single quote. do you get any errors?
Please compare the output from this code with the running command.
wscrip.echo "forfiles /p " &Chr(34) &"z:\" &Chr(34) &" /m *.txt /d -365 /c " &chr(34) &"cmd del /q @file" &Chr(34)
Chr(34) is a single quote. do you get any errors?
Please compare the output from this code with the running command.
wscrip.echo "forfiles /p " &Chr(34) &"z:\" &Chr(34) &" /m *.txt /d -365 /c " &chr(34) &"cmd del /q @file" &Chr(34)
ASKER
can vbscript delete files from a network share without mapping a drive? if so, it'd probably be easier to just write it so that we can delete the files.
yes but what exactly shell be deleted?
ASKER
any file with extension .done that is older than 3 months.
ASKER
no need to recurse sub-directories. folders shouldn't be deleted, just the files.
all text files which are older than 365 days? I don't know the forfiles syntax
ASKER
forfiles /p "PATH" /m *.txt /d -90 /c "cmd del /q @file"
/p and then the path to the files
/m to match the files to be deleted
/d for date. -90 means anything older than 90 days
/c means to run a command and the command is del /q @file"
/q is quiet
@file means to delete the files that were matched in the /m switch
/p and then the path to the files
/m to match the files to be deleted
/d for date. -90 means anything older than 90 days
/c means to run a command and the command is del /q @file"
/q is quiet
@file means to delete the files that were matched in the /m switch
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
AWESOME!!!
Exactly what I wanted. I really appreciate it.
Exactly what I wanted. I really appreciate it.
ASKER
EXCELLENT. Exactly what i needed
Open in new window