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
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 want to use Mediainfo with a bat file.
It should write the Media Info into a textfile, then rename the file to *.nfo
That works quite good, but I always get the complete "standart" Media Info, not a custom one that I need.
Here is my code so far:
#echo off
set "mediainfo_path=C:\Program Files\mi cli\MediaInfo.exe"
set "output_extension=C:\Program Files\mi cli\custom.txt"
cd %1
echo.
echo Looking for Media Assets on target directory . . .
REM ******** Add media file extensions here ********
dir *.mkv /b /s > filelist.tmp
REM *
REM ******* Loop through temporary file list *******
(for /f "delims=" %%i in (filelist.tmp) do (
echo Extracting %%i metadata information . . .
setlocal enabledelayedexpansion
"!mediainfo_path!" --logfile="!output_extension" "%%i" > %%i.nfo
echo()
endlocal
)
del filelist.tmp
echo.
o matter what "output_extenstion" I choose, the result is always the same, full log.
First, you need to do step by step, so start by trying the MediaInfo command without the batch stuff. You'll see that it does not work.
"--logfile" is for storing the output (similar to your ">%%i.nfo") so you did not say to MediaInfo that you want a custom report.
mediainfo --Output=file://custom.txt a.mkv >a.nfo
or
mediainfo --Output=file://custom.txt a.mkv --LogFile=a.nfo
Would work as you expect (the first version both show and store info, the second version only store info).
So replace the "MediaInfo line" by:
"!mediainfo_path!" "--Output=file://!output_extension!" "%%i" > %%i.nfo
and it works as you expect.
Note: I am aware that there is a lack of documentation, due to lack of time :(.
Jérôme, developer of MediaInfo
What I'm trying to do is copy a couple hundred images scattered throughout a directory tree and copy them all to another, single folder. I've found out how to do that with 'for /r %i in (*.jpg) ', but my main issue is that the files are all named using the same conventions. Sample:
Parent_Folder
001
file1.jpg
file2.jpg
002
file1.jpg
file2.jpg
The list continues as such. What I'm aiming to do is create this:
Dest_Folder
001_file1.jpg
001_file2.jpg
002_file1.jpg
002_file2.jpg
where the file's parent directory's name is added to the front of the files (so as to keep them listed in the same order). Not even individually going through every folder and using the "copy & rename" option will work since that will list all files named "file1.jpg" one after the other, "file2.jpg", and so on.
If there's any way to do this in a batch file, that would be much preferred, but a VBScript wouldn't be a bad choice either.
Thanks for any help!
EDIT
Magoo has given the perfect answer for my issue, but it seems his script only works if the source & destination paths have no spaces in them, despite the double quotes. I tried using this same script on another image collection, but with spaces in the paths, and I'm given an error saying the '[word after the first space in the path] was not expected at this time'. It was simple enough to just rename the folders, perform the copy, the rename them back, but is there a workaround for this?
#ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET "sourcedir=c:\sourcedir"
SET "destdir=c:\destdir"
FOR /r "%sourcedir%" %%a IN (*.jpg) DO (
SET "newname=%%a"
SET "newname=!newname:*%sourcedir%\=!"
ECHO COPY /b "%%a" "%destdir%\!newname:\=_!"
)
GOTO :EOF
Grab each filename, remove the source directory name and a \, then copy the file to that name, changing each \ to _.
The required commands are merely ECHOed for testing purposes. After you've verified that the commands are correct, change ECHO COPY to COPY to actually copy the files.
Edit : fixed to allow spaces in sourcedir (simply quote after the /r in the for)
Sub BuildFileName(ParentFolder)
Dim objFSO, objFolder, strFileName
Set objFSO = WScript.CreateObject("Scripting.Filesystemobject")
Set objFolder = objFSO.GetFolder(ParentFolder)
For Each folder In objFolder.SubFolders
For Each file In folder.Files
strFileName = ParentFolder & "_" & folder.Name & "_" & file.Name
WScript.Echo strFileName
Next
Next
End Sub
Call BuildFileName("c:\scripts")
I have a list of files with their full path in a single text file. I would like to open them all at once in Windows. The file extension will tell Windows what programme to use. Can I do this straight from the command line or would I need to make a batch file? Tips on how to write the batch file appreciated.
My text file looks like the following:
J:/630/630A/SZ299_2013-04-19_19_36_52_M01240.WAV
J:/630/630A/SZ299_2013-04-19_20_15_39_M02312.WAV
J:/630/630A/SZ299_2013-04-19_21_48_07_M04876.WAV
etc
The .WAV extension is associated with Adobe Audition, which is a sound editing programme. When each path is hyperlinked in an Excel column, they can be opened with one click. Clicking on the first link will open both Audition and the hyperlinked file in it. Clicking another hyperlink will open the next file in the same instance of the programme. But this is too slow for hundreds of paths. If I open many files straight from R, e.g.
shell("J:/630/630A/SZ299_2013-04-19_19_36_52_M01240.WAV", intern=TRUE)
shell("J:/630/630A/SZ299_2013-04-19_20_15_39_M02312.WAV", intern=TRUE)
etc
each file will be opened in a new instance of the programme, which is nasty. So batch seems preferable.
for /f "delims=" %%a in (yourtextflename) do "%%a"
should do this as a batch line.
You could run this directly from the prompt if you like, but you'd need to replace each %% with % to do so.
It's a lot easier to put the code into a batch:
#echo off
setlocal
for /f "delims=" %%a in (%1) do "%%a"
then you'd just need to enter
thisbatchfilename yourtextfilename
and yourtextfilename will be substituted for %1. MUSCH easier to type - and that's what batch is all about - repetitive tasks.
Following on from this post, which uses the identify function in R to create a subset selection of rows (from a larger dataset called "testfile") by clicking on coordinates in a scatterplot. One of the columns contains the list of Windows paths to original acoustic datafiles. The last line below will open all files in the listed paths in only one instance of the programme linked to the Windows file extension.
selected_rows = with(testfile, identify(xvalue, yvalue))
SEL <-testfile[selected_rows,]
for (f in 1:nrow(SEL)){system2("open",toString(SEL[f,]$path))}
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.