WellingtonIS
asked on
Deleting Files automatically via script
I have 2 bat files I created and scheduled to run. The problem is when the scheduled task kicks off the script runs and nothing happens. When I copy the information into a command prompt it does it job. What am I doing wrong?
script 1 - del /q P:\Integrad\3.0\Data\spool\ResendDICOMImagesQueue_169.123.190.19\*
for /d %x in (P:\Integrad\3.0\Data\spool\ResendDICOMImagesQueue_169.123.190.19\*) do @rd /s /q "%x"
script 2 - del /q P:\Integrad\3.0\Data\spool\DicomSendJob_169.123.190.19\*
for /d %x in (P:\Integrad\3.0\Data\spool\DicomSendJob_169.123.190.19\*) do @rd /s /q "%x"
script 1 - del /q P:\Integrad\3.0\Data\spool\ResendDICOMImagesQueue_169.123.190.19\*
for /d %x in (P:\Integrad\3.0\Data\spool\ResendDICOMImagesQueue_169.123.190.19\*) do @rd /s /q "%x"
script 2 - del /q P:\Integrad\3.0\Data\spool\DicomSendJob_169.123.190.19\*
for /d %x in (P:\Integrad\3.0\Data\spool\DicomSendJob_169.123.190.19\*) do @rd /s /q "%x"
ASKER
It's actually a SAN connected to the device and it's a mapped drive - there's no server and share. I don't think i can.. This has something to do with the actual scheduled task because I can run the script manually and it does it's job.
Wellington,
Have you checked Event Viewer? There might some clues in there.
Have you checked Event Viewer? There might some clues in there.
ASKER
How about this... Does anyone know a powershell command to delete subfolders within a folder:
The folder path is "P:\Integrad\3.0\Data\Spoo l\DicomSen dJob_169.1 23.190.19
There are many subfolders that I need to delete in this folder. So far everything I've tried doesn't delete the subfolders. I can delete the entire root folder but then I have to re-create it. Why is this so complicated??? Ive tried :
Get-ChildItem -Path P:\Integrad\3.0\Data\Spool \DicomSend Job_169.12 3.190.19 -Include *.* -Recurse | foreach { $_.Delete()}
doesn't seem to do it.
The folder path is "P:\Integrad\3.0\Data\Spoo
There are many subfolders that I need to delete in this folder. So far everything I've tried doesn't delete the subfolders. I can delete the entire root folder but then I have to re-create it. Why is this so complicated??? Ive tried :
Get-ChildItem -Path P:\Integrad\3.0\Data\Spool
doesn't seem to do it.
powershell
to delete all files recursively in a folder
to delete all files recursively in a folder
Get-ChildItem -Path C:\Temp\X -Include *.* -Recurse | foreach { $_.Delete()}
The second line of the script above will do exactly that.
Note that I not only changed the drive to UNC, but as well the loop variable from %x to %%x. The single percent sign only works directly in the cmd prompt; in a batch script, two percent signs are required:
Note that I not only changed the drive to UNC, but as well the loop variable from %x to %%x. The single percent sign only works directly in the cmd prompt; in a batch script, two percent signs are required:
del /q \\Server\Share\Integrad\3.0\Data\spool\ResendDICOMImagesQueue_169.123.190.19\*
for /d %%x in (\\Server\Share\Integrad\3.0\Data\spool\ResendDICOMImagesQueue_169.123.190.19\*) do @rd /s /q "%%x"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
powershell
delete all subfolders, keep files in target only...
delete all subfolders, keep files in target only...
$path = "C:\Temp\X"
Get-ChildItem -Path $path -Directory -Recurse| Foreach-object {Remove-item -Recurse -path $_.FullName }
Why is this so complicated??? <<<< It will get better. Hang in there :-)
ASKER
Sorry the task scheduler runs however, nothing happens. But If I run the script manually it works just fine????
ASKER
I"m using Get-ChildItem -Path P:\Integrad\3.0\Data\Spool \DicomSend Job_169.12 3.190.19 -Include *.* -Recurse | foreach { $_.Delete()} so let me try something else.
Replace it with the share it's mapped to, and make sure that the account used to run the task has the required NTFS and Share permissions.
Open in new window