Question

okay my question is rather simple I want to create a batch file or a shell script that will start when a file is saved to the documents folder so that it can sort the file to its specified sub folder. can anyone point me in the right direction with this?

I would prefer to not have to install separate programs, and would like to keep this as a batch.

machine note: OS=Windows 7 pro

Thanks in advance!

EDIT: this code works perfect for what I needed:

    @echo off 
    :A
    CD "desktop\file moving test"
    tree

    move /Y 1*.* 1*
    move /Y 2*.* 2*
    move /Y 3*.* 3*
    goto A 

Thank you to every one who answered.

Was it helpful?

Solution 2

You can either make a batch file, that you use to save the file in the folder, and then run the process you need, or you set it as a windows process, and run a it every n time, to check in differences. If differences are found, then run your logic. Somthing like the following, and compare it to the prior count. I would do it as a scheduled task, that runs your batch file.

@echo off
for /f %%A in ('dir ^| find "File(s)"') do set cnt=%%A
echo File count = %cnt%

OTHER TIPS

All you need is a loop and timeout (Vista and higher) or ping to delay for 5 minutes, and repeat the loop.

@echo off
:loop
  if exist *.txt (
     copy "*.txt" "d:\wherever"
  ) 
timeout 300
goto :loop

For monitoring file changes in the Documents folder you can call this batch-file from a previous scheduled task which you can create with SCHTASK command:

@Echo OFF

REM By Elektro H@cker

PUSHD "%USERPROFILE%\Documents"

:: Recycle past session logs
Del /Q "%TEMP%\FileList.tmp","%TEMP%\FileListNew.tmp"

:Monitor_Loop
If Exist "%TEMP%\FileList.tmp" (
    Dir /B /A-D > "%TEMP%\FileListNew.tmp"
    Echo N | Comp "%TEMP%\FileList.tmp" "%TEMP%\FileListNew.tmp" 1>NUL 2>&1 || (
        Echo File changes found on directory.
        Call :FileOp
    )

    MOVE /Y "%TEMP%\FileListNew.tmp" "%TEMP%\FileList.tmp" 1>NUL

    ) ELSE (

        Dir /B /A-D > "%TEMP%\FileList.tmp"
)

REM Ping -n 5 LOCALHOST 1>NUL
Timeout /T 5 1>NUL & REM Avoid Ping while you are in Windows 7/8.
GOTO :Monitor_Loop

:FileOp
For %%# in ("*") Do (Echo "%%~#")
GOTO:EOF

PS: Just add the operations that you need to perform with the new files found inside the :FileOp procedure.

you maybe would like to use this VBScript file to run the task/batch hidden:

' Run Hidden Process
' By Elektro H@cker

Process   = """" & WScript.Arguments(0) & """"
Arguments = null

For X = 1 to WScript.Arguments.Count - 1
   Arguments = Arguments & " " & _
               """" & WScript.Arguments(X) & """"
Next

WScript.CreateObject("WScript.Shell").Run _
Process & " " & Arguments, 0, False

Wscript.Quit
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top