Copy files from a list.txt, output error log - windows

I have read many posts covering copy and xcopy, but i am unable to get my command to work.
I aim is to create a batch file that will do the following;
Search a directory structure for a list of files 'names only' if found copy them to another directory. If not found create an error list.
The txt format of files I am looking for can be in any format however in testing i have a text file like this;
1603010853
1603020845
1603141400
1604061215
The files are .PDF or .TIF
The directory structure that I am searching is like this;
X:DEL>16>160314>1603141400.pdf
X:DEL>16>160301>1603010853.tif
I am struggling to get it to work as the list is not the full path.
for /f "tokens=*" %i in (File-list.txt) DO xcopy /S/E "c:Test\In%i" "c:out"
Thanks in advance
Fostersimported

Alrighty, if tool doesn't matter much, I'd suggest going with the PowerShell script attached to this SuperUser post. It seems to do everything you want (including logging errors). You'd need only copypasta that into a text file, name it accordingly, and go from there.

Related

Copy an image and rename it to match other file names

I have ZERO bat knowledge so thought I would ask here, if I may.
I have an image C:\Users\Dane\Pictures\Doom.jpg. I wish for this image to be copied and for it to be renamed to the exact name of 379 non-image type files which are in another folder which is G:\Doom. So I will have the same image 379 times but named to match the 379 files.
Would anyone be kind enough to write a bat file to do that? Thank you in advance.
This site is not a free code writing service; Rather give the subject an attempt and we will be happy to assist you. However, because I'm nice, I have a response for you.
This problem is pretty common and can be solved very easily using a FOR statement. In this example we will be searching a directory for every item stored inside. Each item will be added to the integer %%A. For more information do FOR /? inside a command window.
for %%a in ("Directory") DO (Action)
For copying files, we will use the copy command. Please keep note that we will be using parameter extensions to expand the %%A to have no extension using %%~na. More info here: Parameter Extensions
This script will copy & rename Doom.jpg to G:\Doom for each item in the directory.
Batch File:
for %%a in ("G:\Doom\*") do (copy "C:\Users\Dane\Pictures\Doom.jpg" "G:\Doom\%%~na.png")
Command Prompt:
for %a in ("G:\Doom\*") do (copy "C:\Users\Dane\Pictures\Doom.jpg" "G:\Doom\%~na.png")

Command prompt batch renaming results in syntax error

I need to rename 80k files in multiple folders & subfolders in the same directory. I have been trying to use ren but have been unsuccessful; I get an incorrect syntax error.
My old name looks like this:
c:/users/alice/BiDIR_DOCS_2017_Nov08020423\Company,LLC##NA##7967425.00##7967425.00\Company LLC A and A - Aug2017.pdf BiDIR_DOCS_2017_Nov08020423\Company, LLC##NA##7967425.00##7967425.00\document_# (x.y.z)-test~.pdf
and my new name looks like this:
c:/users/alice/BiDIR_DOCS_2017_Nov08020423\Company,LLC##NA##7967425.00##7967425.00\Company LLC A and A - Aug2017.pdf BiDIR_DOCS_2017_Nov08020423\Company, LLC##NA##7967425.00##7967425.00\system, a old name~ ` to # system b document (xyz)-test.pdf
I have the existing directory print in one column of Excel and in the next column what I want the directory print to be.
I'm not sure if I'm starting my ren command at the right hierarchy of my directory, or if I need quotation marks to keep the spaces and symbols in my new name.
I have tried improvising and testing on my own without success and I cannot find an article online on point.
Try FAR (find and replace) - it a free utility that works well.
http://findandreplace.sourceforge.net/

make a windows batch file to create text files from other file names with extra code in it

Edit 3,.
based on aacini's comment, i wrote the following
#echo off
for %%a in ("*.mp4") do echo.>"J:\=Backup Files\testing\%%a.avs"
for %%a in ("*.mp4") do #echo DirectShowSource("%%a.mp4")> %%a.avs
But that had extra .mp4 at the end. so i just delted the .mp4 in above as to get
#echo off
for %%a in ("*.mp4") do echo.>"J:\=Backup Files\testing\%%a.avs"
for %%a in ("*.mp4") do #echo DirectShowSource("%%a")> %%a.avs
does that look ok to everyone?
Edit 2.
I've tried the following.
#echo off
echo.>"J:\=Backup Files\testing\%%a.avs"
#echo DirectShowSource("%%a.mp4")> %%a.avs
That only produces an avs file named %a.avs, and in it, is
DirectShowSource("%a.mp4")
how do i modify this so that it will generate avs for each mp4 files and with the name of the mp4 file appened within the parenthesis on the DirectShowSource command
I need to automatically generate a number of *.avs file which is a text file with its extension changed from txt to avs.
The name of the avs file needs to be the same as another movie file in the folder.
So if you have a movie called
some random movie.mp4
the avs file needs to be named,
some random movie.avs
And the avs file needs to have the following entered in it.
DirectShowSource("some movie name.mp4")
I need to create this type of avs files for many movies in a folder.
I posted this 2 days ago and people put it on hold, so i'm trying it again.
I hope that's not too broad.
Thanks for any help.
This question is still too broad it seems.
Here's an example of something similar.
Create a txt file using batch file in a specific folder
The Op asks how to create text files in a folder.
#echo off
echo.>"d:\testing\dblank.txt"
is one answer given. my problem is that the files needs to have an extension of avs not txt.
Then another posts in the same thread,
#echo off
#echo>"d:\testing\dblank.txt
#echo Writing text to dblank.txt> dblank.txt
To accomplish writing some stuff to the file that's been created. My stuff that needs to be written in the files is
DirectShowSource("some movie name.mp4")
And i need to generate that for all the movies individually with its own names replace the phrase "some movie name"

Search for specific directory names within subdirectories and copy files (Windows batch)

need some help with this one
I have a directory that contains subdirectories from various applications so let's say directory is c:\home and each application has a subdirectory called the application name so we will have
c:\home\app1
c:\home\app2
etc.
These applications write large log files and they then get recreated every hour but into a different directory, called according t date and time like dd/mm/yyyy/hr and this is created within the actual subdirectory and a log file with the exact same name will be within each directory for each app. so we will end up with this
c:\home\app1\1015201410\app1.log
c:\home\app1\1015201411\app1.log
c:\home\app1\1015201412\app1.log
c:\home\app2\1015201410\app2.log
c:\home\app2\1015201411\app2.log
c:\home\app2\1015201412\app2.log
I want to list through the directories every hour and collect the latest log from each application, in other words in this instance I want to collect the following 2 only as they are the latest (end time 12 shows it is the 12th hour)
c:\home\app1\1015201412\app1.log
c:\home\app4\1015201412\app2.log
Now getting the file one by one is easy enough but the script is going to become too long and needs to be edited on a regular base to allow for new applications added to the directories.
I am able to do the copying, formatting the time/date section etc. I just need to find a way to search through the home directories for all subdirectories containing the latest timedate and then copy a file from it elsewhere.
So I tried this. Note timedateformat has been predefined:
for /D %%d in (c:\home\*\%timedateformat%\*) do (
for %%f in (%%d\.log) do (
xcopy %%f C:\destination\
)
)
but this obviously does not like the * part and therefore I will get no result.
Please if anyone is able to assist, I would greatly appreciate.
for /d %%F in ("c:\home\*") do xcopy "%%F\%timedateformat%\*.log" "c:\destination\"

How to search for a .htaccess file with Windows?

I am dealing with a massive nest of files and need to find a .htaccess file that is redirecting a single page in my website. I know how ridiculous this sounds: why not just check the directories the page is located within? But the problem is slightly more complicated than that. All I need though, is to search for every .htaccess file under the web folder. Trying a normal search doesn't allow me to select that type of file to search for, and searching for hidden files has just been (who knows why) ignoring the .htaccess files anyway. I can't download any new software to do this for me. but - there must be a way! Even if I could somehow list every file within a directory (and its subdirs) and then organize by file type and scroll down?
I could search for any file with the word "RewriteEngine" , but there are so many files, this would take forever.
Any ideas?
Thanks!
=/ notepad++ is not installed, and I don't have auth to install anything
Use the commandline.
findstr /s RewriteEngine .htaccess
Searches the current directory and all sub directories for .htaccess files containing the string RewriteEngine.
Try searching for files of the form: *htaccess
(spelled precisely like that in the search field)
have you tried using Notepad++. It has a 'Find in files...' option that you could specify the page that it's trying to redirect to, and you could have it check only in *.htaccess files.
Just a thought
Search All files and folders, in All or part of the filename: put ".htaccess" including the quotes.
in the command prompt:
for hidden files: dir /s /b /a:sh *.htaccess>C:\results.txt
for non-hidden files: dir /s /b *.htaccess>C:\results.txt
to search for "RewriteEngine" type dir /s /b rewriteengine
both of these will output the search results to a text file called "results"

Resources