General discussion

Locked

Need a script to delete files

By Shempdog ·
Hey guys I am new to the forum so any help you can give is appreciated. I am trying to creat a script either .nat or vbscript to delete files that are older then 90 days (based on the date the file was created). I have seen multiple scripts that do this however. I need to be able to search the subdiretories from this folder and only delete them from folders labelled "Outgoing" Any ideas or solutions are aprpeciated.

This conversation is currently closed to new comments.

6 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by Toivo Talikka In reply to Need a script to delete f ...

You can probably manage with .bat files. Here is an example, based on keyboard input of the first file creation date you want to keep in the folders.

How to call the routine:

filedel 07-12-2005

It is assumed that both routines are stored at the root of the directory structure where your Outgoing directories are.

Here is the main routine filedel.bat:

@echo off
set date = %1
@echo date = %date%
@echo press Enter to continue
@echo press Ctrl-C to stop the deletion of older files from Outgoing
pause
@echo starting loop
for /F %%i in ('dir /AD /B /S Outgoing*') do filesub.bat %date% "%%i"
@echo end of loop


... and here is the subroutine filesub.bat:

@echo off
@echo parameter 1: date mm-dd-yyyy %1
@echo parameter 2: directory path %2
@echo create an empty work directory
rmdir /S /Q workdir
mkdir workdir
@echo copy files newer than the date to workdir
xcopy %2\*.* workdir\. /D:%1 /C /Q /K /X
@echo delete all files from directory
del /Q %2\*.*
@echo copy files back from workdir
xcopy workdir\*.* %2\. /C /Q /K /O

Enjoy!

Collapse -

by Toivo Talikka In reply to

Oops, the main routine may not always work. Replace it with this version which prompts for the date, instead of getting it as a command line parameter:

@echo off
set /P date_in=Enter date dd-mm-yyyy:
@echo date = %date_in%
@echo press Enter to continue
@echo press Ctrl-C to stop the deletion of older files from Outgoing
pause
@echo starting loop
for /F %%i in ('dir /AD /B /S Outgoing*') do filesub.bat %date_in% "%%i"
@echo end of loop

Collapse -

by Shempdog In reply to

The answer was sound and it actually works, I had already figured it out myself. But I promised the points, and He'll get them

Collapse -

by Shempdog In reply to Need a script to delete f ...

Thanks for the help, I actually figured it out myself using vbscript. I am sure however the batch file you showed me will come in handy in the future!

Collapse -

could you please send the VB scriptwhich

by arihantsurana4u In reply to

could you please send the VB script which takes the back up of the files which are older than a week, 7 days from one folder on the network and then deletes these files from the source folder, .
Help will be much appreciated, as i need this script in a very short time.Tried out various script can't fulfill both of my purposes i.e. >
1) taking the backup of the files in a particular folder, datewise
2) delete from the source directory.

Thanks in advance.

Collapse -

by Shempdog In reply to Need a script to delete f ...

This question was closed by the author

Back to Desktop Forum
6 total posts (Page 1 of 1)  

Related Discussions

Related Forums