Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Newbie needs help! (batch file)  (Read 3748 times)

0 Members and 1 Guest are viewing this topic.

gin8u

    Topic Starter


    Starter

    Newbie needs help! (batch file)
    « on: April 21, 2010, 08:16:21 PM »
    I'm in the process of learning DOS.

    In its simplest form, i need to:
    1. If there's a file that exists, i need to check it if it exists, if it does i need to rename it with a .txt extension and place it into a directory. then write a note in log file.

    2. if there isn't a file that doesn't exist, i need to create a directory. then write it in a log

    3. i need to copy only modified files from one directory to another


    If anyone can help it would be very much appreciated.

    thanks

    gin8u

      Topic Starter


      Starter

      Re: Newbie needs help! (batch file)
      « Reply #1 on: April 21, 2010, 08:41:07 PM »
      does this make sense?

      Code: [Select]
      If exist "c:\temp\MyPlace\*.*" (
      rename *.* *.FIL >> m.log
      ) else (
      md c:\temp\MyPlace >> m.log

      xcopy m:\*.* c:\temp\MyPlace\*.* /d /y

      Helpmeh



        Guru

      • Roar.
      • Thanked: 123
        • Yes
        • Yes
      • Computer: Specs
      • Experience: Familiar
      • OS: Windows 8
      Re: Newbie needs help! (batch file)
      « Reply #2 on: April 21, 2010, 08:42:23 PM »
      1.
      @echo off
      if exist FILENAME (
           ren FILENAME FILENAME.TXT
           Copy FILENAME.TXT DIRECTORY
           Echo File found. > log.txt
      )
      2. If there isn't a file that doesn't exist? So, you have a list of files that need to exist? Ok.

      @echo off
      set list=put the path to where the required file names are in. Eg. Files.txt
      setlocal enabledelayedexpansion
      for /f "delims=" %%a in (%list%) do (
           Set /a counter+=1
      )
      for /f "delims=" %%b in (%list%) do (
           If exist %%a (
                ren %%a %%a.txt
                Copy %%a.txt DIRECTORY
                echo File found > log.txt
                Set /a counter2+=1
           )
      )
      If %counter% neq %counter2% (
           Echo Not all files found. >log.txt
           Md DIRECTORY
      )
          
      3. Look at XCOPY /? at the command prompt. Also, try looking through the forum. You will probably find something to your requirements.  
      Where's MagicSpeed?
      Quote from: 'matt'
      He's playing a game called IRL. Great graphics, *censored* gameplay.

      gin8u

        Topic Starter


        Starter

        Re: Newbie needs help! (batch file)
        « Reply #3 on: April 21, 2010, 08:51:19 PM »
        thanks for this!

        for #2.
        it's more like if FILENAME or DIRECTORY don't exist, create the directory (and the file) and write in a log file.