Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi all! We have been experiencing an issue on site where threads have been missing the latest postings. The platform host Vanilla are working on this issue. A workaround that has been used by some is to navigate back a page or two to re-sync the thread and this will then show latest posts. Thanks, Mike.

Dos Help

  • 24-05-2005 12:03am
    #1
    Registered Users, Registered Users 2 Posts: 68 ✭✭


    I would like to delete every file listed in a text document (potentially thousands). I thought the best way to do this is with a batch file. Pass each line in the file as a parameter to a For loop.

    I referenced the help and google so please nobody come back and say use google, lazy.

    I have been tinkering with this line
    for /F "eol=; TOKENS=2,3,* delims=,"%1 in test1.txt do @echo %i %j %k

    the file test1.txt contains

    DEL D:\Media\Music\PIC.jpg
    DEL D:\Media\Music\PIC1.jpg
    DEL D:\Media\Music\PIC2.JPG


    I keep getting thE message ...IN WAS UNEXPECTED AT THIS TIME


Comments

  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 92,385 Mod ✭✭✭✭Capt'n Midnight


    in a batch file you have to use %%

    for /F "eol=; TOKENS=2,3,* delims=,"%1 in test1.txt do @echo %i %j %k

    also your %1 should be %%i .... echo %%i %%j %%k etc.

    oh don't forget quotes around file names to be on the safe side

    eg; del "c:\program files\spyware\"


  • Registered Users, Registered Users 2 Posts: 78 ✭✭de8o


    Up to your usual high standards Capt'n Midnight. However aren't you over complicating things. If the .txt file is renamed to a .bat file and run it would surely do the same as it has DEL before filename.

    Also alancool depending on how this text file is create you may want to add /q

    DEL /q filename

    just in case...


  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 92,385 Mod ✭✭✭✭Capt'n Midnight


    Yeah if the del is there ain't much point - but the OP did want to delete files in a list and it saves the effort of inserting DEL on each line

    generate and filter a list - you could also use Xcopy /L and the Exclude list as another way of generating a list of files to copy/delete/process
    DIR /B >List
    find /i "keyword" <list >list2
    find /v /i "keep" <list2>list3
    notepad list3


  • Registered Users, Registered Users 2 Posts: 68 ✭✭alancool


    DIR /B >List
    find /i "keyword" <list >list2
    find /v /i "keep" <list2>list3 :confused:
    notepad list3

    Please pardon this question but what is the purpose of the 2nd last line in this batch file, is it to refine the list further?

    Thanks 4 your contribution de8o that was an obvious work around but I didn't spot it, tanx :o
    But i still want to pass each line of the list (which now contains just the file path and name) to the for loop.

    As you instructed Capt'n Midnight I doubled up on % signs but to no avail. the batch file now looks like

    for /F "eol=; TOKENS=2,3,* delims=, " %%1 in test1.txt do @echo %%i %%j %%k

    and the DOS output reads

    D:\Media\Music>test1
    test1.txt was unexpected at this time

    D:\Media\Music>for /F "eol=; TOKENS=2,3,* delims=, " %%1 in test1.txt do @echo %%i %%j %%k

    D:\Media\Music>


    Any other ideas? :confused:


  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 92,385 Mod ✭✭✭✭Capt'n Midnight


    alancool wrote:
    for /F "eol=; TOKENS=2,3,* delims=, " %%1 in test1.txt do @echo %%i %%j %%k

    The two FIND lines are if you want to include / exclude files based on keywords in the name

    you use one % on the command line
    and two %%'s in a batch file - it's an annoyance when testing stuff out


    %0 means the batch file name
    %1 means the next word on the command line when you call the file !
    Echo Hello from %0 - Processing input file %1
    for /F "tokens=1* delims=" %%a in (%1) do echo %%a

    using space as a delim will cause problems when you hit a file with a space in it's name.. :( - getting these right is a real pain when calling another file

    dir /b > file.txt
    for /F "tokens=1* delims=" %%a in (file.txt) do echo %%a

    tokens=1* - puts the entire line in %a
    delims=" - ignore spaces etc.

    you could do something like
    dir /s/b - the /s gets all subdirs and drive letter
    for /F "tokens=1,2* delims=:" %%a in (file.txt) do echo %%a %%b
    %a will be the letter and %%b the file name

    the full file name would be "%%a:%%b"


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 68 ✭✭alancool


    oh Capt'n my Capt'n cheers for that worked a treat its very much appreciated! :cool:


Advertisement