Code: echo. FOR /F "tokens=*" %%D IN ('DIR "C:\Program Files\thefilel" /S /B') DO copy /Y "thefile" "%%D" pause I want this to auto check that "c" is the root and if its not put the file in say D or whatever.
still stuck; all I want it to do is check in the root drive for a file and if its not there then pop up "fail" and if it is there replace it, so far it always "fails" even though the file is in the directory. Ive tried it with %systemroot\Program Files\blah\blah\% >nul and %systemroot%\Program Files\blah\blah\% >nul
%systemdrive% (not %systemroot%) variable equals whatever drive letter the running OS is on. make sure "%systemdrive%\Program Files\blah\blah\blahl" on script
thanks people, but I can get it to work either way, before I pull any more hair out what my plan was is to create a .cmd that checks for a file then if it is there replace it with a file of the same name, that I know can be done but can I wrap the .cmd with the file to be copied in to an exe with Bat_To_Exe_Converter and the cmd when launched as exe will still be able to access the file to be copied from within the exe?
Bat_To_Exe_Converter presumably allows you to insert the "replacement" file beside the ".cmd" file, so upon extraction it should extract both files to the same temp folder, thus file should copy without problem. (The "cmd when launched as exe" is not really launched as exe ... it is just extracted to temp folder). personally, I think bat to exe software is a waste of time, as I think they just extract files to users temp folder, the same as a Winrar sfx installer can do, only many trigger av alarms. EXAMPLE Code: @echo off if exist "%systemdrive%\Program Files\blah\blah\blahl\Test.txt" ( takeown /F "%systemdrive%\Program Files\blah\blah\blahl\Test.txt" >nul icacls "%systemdrive%\Program Files\blah\blah\blahl\Test.txt" /GRANT *S-1-1-0:F >nul del /F /Q "%systemdrive%\Program Files\blah\blah\blahl\Test.txt" >nul copy /Y "%~dp0Test.txt" "%systemdrive%\Program Files\blah\blah\blahl\" >nul echo. echo Successfully Patched ping -n 7 127.0.0.1 >nul goto :end ) else ( echo. echo Failed to Find File to Patch ping -n 7 127.0.0.1 >nul ) :end exit change Test.txt to name of file you wish to check|replace.
^^Well that just closes the cmd window (without coping) and I cant figure out why, nevertheless I think a better approach would be to 1) check for the file 2) if present rename to "backup" if not there then display message saying so 3) copy replacement file to the directory then display conformation message 4) from a new menu delete the copied file and rename backup to original, anyone????????
yeh, wondering if its to do with where the copied file is?, its in a folder with the cmd, the window just closes with no done/not done msg..................
Have you got the file Test.txt in program files\blah\blah\bahl folder, and also alongside the batch file your running ?
yeh, tried it with the file removed from the destination as it should just do nothing in that instance and tried it with the file in the destination, both times (well multiple times) the file to be copied was in the cmd folder, its strange as there is no error at all just an immediate close, with the other parts of the app I got "file" errors and echo errors till it was debugged.
How about using %programfiles% instead of %systemdrive%\program files ie: Code: @echo off if exist "%programfiles%\blah\blah\blahl\Test.txt" ( takeown /F "%programfiles%\blah\blah\blahl\Test.txt" >nul icacls "%programfiles%\blah\blah\blahl\Test.txt" /GRANT *S-1-1-0:F >nul del /F /Q "%programfiles%\blah\blah\blahl\Test.txt" >nul copy /Y "%~dp0Test.txt" "%programfiles%\blah\blah\blahl\" >nul echo. echo Successfully Patched ping -n 7 127.0.0.1 >nul goto :end ) else ( echo. echo Failed to Find File to Patch ping -n 7 127.0.0.1 >nul ) :end exit
Still just dies, tried first removing all >nul's then with just 1 >nul at a time, tried the script as is and as a :thing in my app......... edit, put a @color 90 under the echo and I get a flash of blue now but nothing else..............
just this one, the app that I want this for already has a few things in it, this is the last part but I need to duplicate this about 40 times for the various dll files and locations.....................
works fine for me .... Click Image to see Test of Example code (when at web page, click "View full screen") are you adding code to an "existing" script with improper instruction, causing no message ? ie. "FSUTIL /i "blah" %systemroot\Program Files\blah\blah\% >nul" post #4
I am adding it as a choice to do from a previous menu; :blah CLS if exist "%program......... so picking "A. blah" from a sub menu gives the copy over action.