General discussion

  • Creator
    Topic
  • #2189944

    Need a script to delete files

    Locked

    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.

All Comments

  • Author
    Replies
    • #3069811

      Reply To: Need a script to delete files

      by toivo talikka ·

      In reply to Need a script to delete files

      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!

      • #3069714

        Reply To: Need a script to delete files

        by toivo talikka ·

        In reply to Reply To: Need a script to delete files

        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

      • #3068951

        Reply To: Need a script to delete files

        by shempdog ·

        In reply to Reply To: Need a script to delete files

        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

    • #3068952

      Reply To: Need a script to delete files

      by shempdog ·

      In reply to Need a script to delete files

      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!

      • #2943270

        could you please send the VB scriptwhich

        by arihantsurana4u ·

        In reply to Reply To: Need a script to delete files

        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.

    • #3068950

      Reply To: Need a script to delete files

      by shempdog ·

      In reply to Need a script to delete files

      This question was closed by the author

Viewing 2 reply threads