windows batch programming
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: windows batch programming

  1. #1
    Join Date
    Mar 2010
    Posts
    1

    windows batch programming

    Dear all, I need your help please

    I have a batch file on windows.
    I need to read from a text file a list of file names, the content of the text file is for example filename1;filename2;filename3


    Then, i need to verify in a directory that is an input parameter in the script if the physical files which names are listed in the text file (filename1,filename2...)
    exist in this directory; and write output to a text file a message indicating if each file is found or not.

    The code i wrote but did not return the desired result is:

    Code:
    @ECHO OFF
    echo %date%,%time% Generate list of available and unavailable files >.\log.txt
    
    :start_of_file
    SET /P src_dir="Enter the absolute path for Source Directory where Files are present (including the final \ ): [e.g: .\DATA\RD\]:"
    SET /P src_file="Enter the name of file including the list of the names of files (including the extension e.g: .txt):" 
    
    ECHO The list of files are in %src_file%
    ECHO The physical files are in %src_dir%
    set COUNTER=0
    :TEST
    FOR /F "delims=;" %%A IN (%src_file%) DO( 
    set /a COUNTER+=1
    set FILENAME!COUNTER!=%%A
    goto TEST_FILE_EXISTENCE
    )
    
    
    :TEST_FILE_EXISTENCE
    IF EXIST %src_dir%%FILENAME% (
    ECHO The file you are looking for %FILENAME% has been found in %src_dir%>>.\log.txt
    GOTO TEST
    ) ELSE (
    ECHO The file you are looking for %FILENAME% has not been found in %src_dir%>>.\log.txt
    GOTO TEST
    )
    Can someone help me please?
    regards to all

  2. #2
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,860

    Re: windows batch programming

    [ moved thread ]
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Mar 2010
    Posts
    8

    Re: windows batch programming

    Can you post a sample text file?

  4. #4
    Join Date
    Mar 2010
    Posts
    8

    Re: windows batch programming

    First of all, check what you have in the text file.
    Second, you create the variable %FILENAME1%, %FILENAME2%, %FILENAME3% etc.
    This is because you add the the counter to the variable in set FILENAME!COUNTER!=%%A.

    IF EXIST %src_dir%%FILENAME% will not work in this case.
    There are many ways to solve this but you could try to include the TEST_FILE_EXISTENCE script in the FOR /F "delims=;" %%A IN (%src_file%) DO( loop.

    Hope it helps

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center