Announcement

Collapse
No announcement yet.

Batch Script: Delete files based on files listed in a text document

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Batch Script: Delete files based on files listed in a text document

    Hi Guys & Gals,

    Got an odd one that I'm hoping some guru out there can help me with.
    I have had a request by one of my colleagues to add functionality to a batch script I have written for a client.

    We want to be able to delete music files based on file names in a plain text document.
    Or
    Delete all other music that isn't inside the plain text file.

    If anyone could help me with this I would be most appreciative.

    Cheers.

  • #2
    Re: Batch Script: Delete files based on files listed in a text document

    If you would care to post your script (as a text file or in code tags), we may be able to help
    At the moment it is a bit difficult to work out what you want to do
    Tom Jones
    MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
    PhD, MSc, FIAP, MIITT
    IT Trainer / Consultant
    Ossian Ltd
    Scotland

    ** Remember to give credit where credit is due and leave reputation points where appropriate **

    Comment


    • #3
      Re: Batch Script: Delete files based on files listed in a text document

      Originally posted by Fr0stb1t3 View Post
      We want to be able to delete music files based on file names in a plain text document.
      Or
      Delete all other music that isn't inside the plain text file.
      If you built the above logic into the script then the "Delete All other music that isn't inside the plain text file" would delete anything in the plain text file anyways.

      A simple del *.mp3 would suffice. (obviously add all the relevant music file extensions)

      But perhaps you mean something else?
      Regards,
      Jeremy

      Network Consultant/Engineer
      Baltimore - Washington area and beyond
      www.gma-cpa.com

      Comment


      • #4
        Re: Batch Script: Delete files based on files listed in a text document

        Originally posted by Ossian View Post
        If you would care to post your script (as a text file or in code tags), we may be able to help
        At the moment it is a bit difficult to work out what you want to do
        Sorry I have no code for the question I asked as I don't know how to go about it.
        Originally posted by JeremyW View Post
        If you built the above logic into the script then the "Delete All other music that isn't inside the plain text file" would delete anything in the plain text file anyways.

        A simple del *.mp3 would suffice. (obviously add all the relevant music file extensions)

        But perhaps you mean something else?
        Yes, I mean something else.
        I'll explain what I'm trying to do in more detail.

        A client has a set of music (Mp3 and WAV files) that is played on their system.
        I have created a script which goes in and downloads music and playlists from an FTP sourced inside the company (all legal music).

        What we would like to do is have a script that looks inside a text file which contains all the music file names that they have on their system, if there is any other music in the directory that is not contained within the text file it is deleted.

        The systems will be locked down but there is always a workaround to security so users may load their own music, we want to stop this from happening.

        I hope this paints a clearer picture for what I'm trying to get done.

        Comment


        • #5
          Re: Batch Script: Delete files based on files listed in a text document

          OK, the "add functionality to a batch script I have written for a client" fooled me....

          Something like this (not proper code)
          Assumes all the music you want is in the directory

          Code:
          For each line in text file
          Copy named mp3 to temp directory
          Next line
          Delete whole of original directory contents
          Move temp directory contents into original directory
          Tom Jones
          MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
          PhD, MSc, FIAP, MIITT
          IT Trainer / Consultant
          Ossian Ltd
          Scotland

          ** Remember to give credit where credit is due and leave reputation points where appropriate **

          Comment


          • #6
            Re: Batch Script: Delete files based on files listed in a text document

            Originally posted by Ossian View Post
            OK, the "add functionality to a batch script I have written for a client" fooled me....

            Something like this (not proper code)
            Assumes all the music you want is in the directory

            Code:
            For each line in text file
            Copy named mp3 to temp directory
            Next line
            Delete whole of original directory contents
            Move temp directory contents into original directory
            That is a good idea, hadn't thought of that. Thank you.
            Next step is how do I get the script to read the text file and move the files haha.

            The script I was referring to originally about adding functionality was one which logs in to the FTP server and downloads music.

            Comment


            • #7
              Re: Batch Script: Delete files based on files listed in a text document

              will be a good friend here!

              What scripting language?

              I always think problems backwards, so it made sense to deal with the ones you want and mass cull the rest!
              Tom Jones
              MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
              PhD, MSc, FIAP, MIITT
              IT Trainer / Consultant
              Ossian Ltd
              Scotland

              ** Remember to give credit where credit is due and leave reputation points where appropriate **

              Comment


              • #8
                Re: Batch Script: Delete files based on files listed in a text document

                Originally posted by Ossian View Post
                will be a good friend here!

                What scripting language?

                I always think problems backwards, so it made sense to deal with the ones you want and mass cull the rest!
                Yea now that I have a better idea I think I will use this.

                Code:
                for /F "delims=" %%i in (Music.txt) do (
                echo %%i
                move "%%i" x:\temp
                )
                Delims of course helps with the issues of spaces and whatnot.
                Thanks for your assistance Ossian.

                I have been lurking around Petri.il for years picking up bits and pieces of knowledge but never joined till now.

                Moderator edit:
                This thread continues here in the PowerShell forum.
                Last edited by Rems; 6th June 2010, 13:50.

                Comment

                Working...
                X