We changed a DLL used by many windows programs.
I would like to create a script to replace all occurrences within all subfolders in various paths on our servers.
Below is a start on the script i need help with
setlocal enabledelayedexpansion
SET FromFile = "\\servernameFrom\folder\some.dll"
SET ToLocations = "\\servername1\sharename\" "\\servername2\sharename\" "\\servername2\sharename\"
for /l %%loc in (0,1,2) do (
echo Working on !ToLocations[%%loc]!
REM now do the recursive copy for that
for /r !ToLocations[%%loc]! %%f in (.) do (
copy FromFile "%%~ff" > nul
)
)
Related
i have 1000 photos with extension .jpg and every name of photo is a code like this 12345.jpg.
And i have 1000 folders with names like this: text_text_text_code(000000)
the job is put every photo in every single folder, i can solve this, but not working very well.
I found the problem, but i don't know how to solve.
in name folder i have text_text_text_code(000000), i need the code to stop when it arrives at character (.
#echo off
chcp 1250
echo.
echo.
cd "C:\Users\folderexample\Desktop\123"
for /r "C:\Users\folderexample\Desktop\imagem" %%a in (*.jpg) do (
for /f %%b in ('dir /b *"%%~na"*') do copy "%%a" "%%~fb"
)
I would like the search to go to the character ( and go to next search up until finish photos.
I am trying to write a command script to do the following. For each file in a specific directory, I want to get the filename and the size of the file. If the filename is what I am looking for and the file size is greater than zero, I want to process the file.
I can get the filename fine but I cannot get the file size without using the recursive switch.
This code works but I don't want it to look in subdirectories:
for /f "delims=" %%f in ('dir /s /b /a-d "%input_directory%" ') do (
set filename=%%~nxf
set filesize=%%~zf
)
I've looked around but have been unable to find what I need. Any help would be appreciated.
I finally figured it out. Here's what I used to get the job done.
for /f "tokens=*" %%f in ('dir /b "%input_directory%" ') do (
set filename=%%~nf
if !filename!==somename (set validname=Y)
if !validname!==Y (
for %%a in ("%input_directory%\!filename!") do (
set filesize=%%~za
if !filesize!==0 (
log as empty file
) else (
process file
)
)
)
)
I need a script that checks the name of a CDG file and if is not present in the same folder another file with the same name in .mp3, then deletes the cdg file.
I thought to implement it with this simple code:
#echo off
for /R %1 %%f in (*.cdg) do (
if exist %%~nf.mp3 (
del %%f
)
)
But it return me with a syntax error in IF construct.
I tried to google it but it seems no-one had same problem (or i'm really bad in using google)
Can please someone tell me where i'm wrong?
Ok, heres an easy way of doing this with forfiles if your using Windows 7:
forfiles /m "*.cfg" /c "cmd /c if exist #fname.mp3 del #path"
That alone should work fine, and it's short enough to be typed directly in cmd.
Mona
It may be due to the name of the file containing spaces. If so then:
#echo off
for /R %1 %%f in (*.cdg) do (
if exist "%%~nf.mp3" (
del %%f
)
)
NB : Quotation Marks
Also, You should look into forfiles (since you'll only be needing one line of code) but that will only work if your using Windows 7.
Mona
Give this a whirl:
#echo off
for /R "%~1" %%f in (*.cdg) do (
if exist "%%~dpnf.mp3" (
del "%%f"
)
)
I am writing a dos script and I want to get the path of a file that is known so that the path can be used within the script to change to that directory to use the file specified and ouput log files to the same directory.
The script adds some directories to the path and changes to the required directory to execute a command using input files in the same directory. The command generates a number of files that are saved to the same directory.
Here is what i have so far
#ECHO OFF
:: Check argument count
set argC=0
for %%x in (%*) do Set /A argC+=1
IF %argC% LSS 3 (echo WARNING must include the parent Directory, the filename and the timestep for the simulation)
:: Assign meaningfull names to the input arguments
set parentDirectory=%1
set filename=%2
set scenarioTimestep=%3
:: Check validaty of the input arguments
:: TODO: implement check for directory, filename exists, and possibly limits to the timestep
IF "%parentDirectory%"=="" (
set parentDirectory=P:Parent\Directory
)
IF "%filename%"=="" (
set filename=ship2.xmf
)
IF "%scenarioTimestep%"=="" (
set scenarioTimestep=0.1
)
echo parent Directory: %parentDirectory%
echo filename: %filename%
echo timestep: %scenarioTimestep%
set MSTNFYURI=file:mst.log
set MSTNFYLEVEL=debug
set MSTNFYFLUSH=1
set XSFNFYURI=file:xsf.log
set XSFNFYLEVEL=debug
set XSFNFYFLUSH=1
set parentNFYURI=file:parent.log
set parentNFYLEVEL=debug
set parentNFYFLUSH=1
:: Add the parent directories to the path
set PATH=%parentDirectory%\bin\;%parentDirectory%\bin\ext\;%parentDirectory%\bin\gtkmm\;%parentDirectory%\bin\osg\;%PATH%
:: Change to the target directoy
set tagetDirectory=%parentDirectory%\examples\testing_inputs
cd %tagetDirectory%
echo command will be: ft -c %filename% -T %scenarioTimestep%
::ft -c %filename% -T %scenarioTimestep%
#ECHO ON
What i want to be able to do is instead of using the hard coded directory path examples\testing_inputs for targetDirectoy, i want to be able to search for the filename supplied and change directory to that path.
I know i can get the information displayed using
"dir filename.ext /s"
DOS ouptut
Volume in drive C is OS
Volume Serial Number is XXXX-XXXX
Directory of C:\Users\Me\parent\examples\testing_input
15/11/2012 02:51 PM <size> filename
...
...
How do i extract the directory form this info to be used within the script? Also if there is more than one file of the same name, how can i select the path based on the timestamp of the file?
for /f %%F in ('dir /B /S /A:-D filename.ext ') do set file_path=%%F
pushd %file_path%\..
dir_path=%CD%
popd
echo %file_path%
echo %dir_path%
is this what you looking for?
EDIT: Check dbenham's comment.
I am trying to write an aspx page which will crawl through a directory and find all the files contained within. I think I have that part down.
Is it possible to read to a string without first creating .txt files from the html and asp pages I'm reading through? I don't want to create a ton of new files and then end up having to delete them later.
Ultimately, I'm trying to develop a tool to search through an entire directory and find all the image tags which have empty alt attributes or no alt attributes. I wrote some jQuery which can find the tags, and I have also written the part that searches through a directory.
If you have a file on your filesystem, you can simply read it - if you know it is a textual format, you need to use a stream with the correct encoding to do this.
Since you are reading and querying HTML, I suggest using a library that is specifically written for this task - the HTML Agility Pack - you can give it the path to the HTML file and then query it for all img elements. The source download comes with sample projects that will show you how to achieve this and other tasks.
Link:
http://msdn.microsoft.com/en-us/library/system.io.streamreader.aspx
Example:
http://www.csharp-examples.net/load-text-file-to-string/
(this example shows how to work with .txt files, but I believe if you can put any other extension)
Getting all files:
http://www.csharp-examples.net/get-files-from-directory/
Edit: and don't forgot about encoding.
sure, why not save to environment variables, no fuss, no mess. so try something like this:
will take apart an html or asp file and save to an array of variables, i have shown you how to put it back together as well.
let me know how if this is a solution for you
#echo off
setlocal EnableDelayedExpansion EnableExtensions
echo.
set count=0
if exist newfile.html del newfile.html
:: to unassemble
for /f "tokens=*" %%a in (filename.html) do (
echo %%a
set /a count=count + 1
set htmllinenum!count!=%%a
)& set finalcount=!count!
:: to assemble
for /l %%a in (1,1,%finalcount%) do (
echo !htmllinenum%%a!>>newfile.html
)
notepad newfile.tmp
set count=0
if exist newfile.asp del newfile.asp
:: to unassemble
for /f "tokens=*" %%a in (filename.asp) do (
echo %%a
set /a count=count + 1
set asplinenum!count!=%%a
)& set finalcount=!count!
:: to assemble
for /l %%a in (1,1,%finalcount%) do (
echo !asplinenum%%a!>>newfile.asp
)
notepad newfile.asp