Forums before death by AOL, social media and spammers... "We can't have nice things"
|    alt.msdos.batch.nt    |    Fun with Windows NT batch files    |    68,980 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 67,200 of 68,980    |
|    JJ to Paul Emmons    |
|    Re: Is file movable before being moved?    |
|    09 May 18 04:28:04    |
   
   From: jj4public@vfemail.net   
      
   On Tue, 08 May 2018 06:47:53 GMT, Paul Emmons wrote:   
   > I have a batch program that copies groups of files to two other   
   > drives and then moves them to another directory on the source   
   > drive. Occasionally it does not completely succeed because one of   
   > the target files is in use by a program. Now that the MOVE command   
   > returns errorlevel 1 if there is any problem, it should be possible   
   > to detect this condition early on, inform me, and abort.   
   >   
   > One way, I suppose, is first to move the files to a temporary   
   > directory used only by this batch program, note the errorlevel, and   
   > move them back to the original location. But I wonder whether   
   > there is a way to determine whether a file can be moved without   
   > actually trying to move it. (The desired files are indicated by   
   > an argument with question marks and asterisks. After they are   
   > moved to the ultimate destination directory, an attempt to move or   
   > copy them from there might conceivably involve other files that   
   > should not be touched.)   
      
   CMD alone doesn't have the capability to check whether a file/directory is   
   really movable/deletable or not.   
      
   My suggestion is to use a VBScript for checking that. Below VBScript will   
   check the given file/directory, and return an exit code which can be checked   
   using ERRORLEVEL or the %ERRORLEVEL% variable.   
      
    set fso = createobject("scripting.filesystemobject")   
    on error resume next   
    if fso.folderexists(wscript.arguments(0)) then   
    set d = fso.getfolder(wscript.arguments(0))   
    n = d.name   
    d.name = n & "z"   
    e = err.number   
    if e = 0 then d.name = n   
    else   
    set f = fso.opentextfile(wscript.arguments(0), 8, false, 0)   
    e = err.number   
    if e = 0 then f.close   
    end if   
    wscript.quit e   
      
   The possible exit codes are:   
    0 = OK. Specified file/directory is movable.   
    53 = Error. Specified file/directory is invalid or doesn't exist.   
    70 = Error. Specified file/directory is not movable.   
   424 = Error. No file/directory given.   
      
   Example usage:   
      
    @echo off   
    setlocal   
    set src=c:\my data   
    set mask=*.doc   
    set dest=d:\my archive   
    rem move files   
    for %%A in ("%src%\%mask%") do (   
    cscript check.vbs "%%A"   
    if %errorlevel% == 0 (   
    rem do file move. e.g.   
    rem move "%%A" "%dest%"   
    )   
    )   
    rem move a directory   
    cscript check.vbs "%src%\subdir"   
    if %errorlevel% == 0 (   
    rem do directory move. e.g.   
    rem move "%src%\subdir" "%dest%"   
    )   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca