Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Help mefind and copy files in 'failed' list.  (Read 3346 times)

0 Members and 1 Guest are viewing this topic.

Geek-9pm

    Topic Starter

    Mastermind
  • Geek After Dark
  • Thanked: 1026
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Help mefind and copy files in 'failed' list.
« on: March 14, 2017, 11:35:53 AM »
I have a TXT  fille with entries like this:
Quote
Failed to import Media “EpsonR300”
Failed to import Media “My-Destop”
Failed to import Media “teen_cell”
Failed to import Media “e-mail”
Failed to import Media “My-Destop”
Failed to import Media “wjy_linux”
I want a script that find find any of the files in the D: drive and copy them to my empty F: drive.  There are about 70 files that were not found.If they can be found, they ought to be on the D: drive.
Duplicate files and not an issue. It could just overwrite any duplicate.
The script does not have to be perfect or elegant. Just do the job. Put thefiless in one place and I will upload them to the server.

Some of you have likely already done this kind of thing.
But forgot. I think.  Maybe I forgot more than what I knew.
Any ideas? Batch? Python? Powershell? 
Thank you  :)


Squashman



    Specialist
  • Thanked: 134
  • Experience: Experienced
  • OS: Other
Re: Help mefind and copy files in 'failed' list.
« Reply #1 on: March 14, 2017, 03:12:15 PM »
That looks like a folder list.

Geek-9pm

    Topic Starter

    Mastermind
  • Geek After Dark
  • Thanked: 1026
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: Help mefind and copy files in 'failed' list.
« Reply #2 on: March 14, 2017, 03:38:17 PM »
Yes, it does. But it really is a list of images where the type of the image is not given. So It means I have to look for image files with just name only, not  type.
So, how do I :
Find a file in a list?
When a file is found, copy it. Or just goon.
Repeat until end of list.

What might the code be?




Hackoo



    Hopeful
  • Thanked: 42
  • Experience: Expert
  • OS: Windows 10
Re: Help mefind and copy files in 'failed' list.
« Reply #3 on: March 16, 2017, 07:17:57 AM »
Hi  ;)
Before trying to provide you a sample code ; can you confirm me that the delimiters between those words to be searched is between “” and not between simple quote ""
If yes try me out this piece of code to confirm that you can retrives those name with the for command

Code: [Select]
@echo off
set "FailedLog=test.txt"
for /f "tokens=2 delims=“”" %%a in ('Type "%FailedLog%"') do (@echo %%a)
pause
« Last Edit: March 16, 2017, 08:22:51 AM by Hackoo »

Hackoo



    Hopeful
  • Thanked: 42
  • Experience: Expert
  • OS: Windows 10
Re: Help mefind and copy files in 'failed' list.
« Reply #4 on: March 16, 2017, 08:47:05 AM »
Give a try for this batch script :

Code: [Select]
@echo off
Title Searching for a specific file name and copy them to a new location
Mode con cols=90 lines=20 & color 9E
set "FailedLog=test.txt"
Set "Location=D:\"
Set "Destination=F:\"
set "LogSearch=%~dp0%~n0.txt"
If exist "%LogSearch%" Del "%LogSearch%"
Cls
echo(
echo       --------------------------------------------------------------------------
echo              Please Wait a while ....... Searching is in progress .........
echo       --------------------------------------------------------------------------
Rem We extract the file name from the failed log file and we perform a search with the
Rem command Where
setlocal ENABLEDELAYEDEXPANSION
for /f "tokens=2 delims=“”" %%a in ('Type "%FailedLog%"') do (
Set "FileName=%%a"
Where /R %Location% "*!FileName!*" /F >>"%LogSearch%" 2>&1
)
If "%ErrorLevel%"=="1" (
Cls
echo(
echo       --------------------------------------------------------------------------
echo                         No file(s^) found with this Pattern
echo       --------------------------------------------------------------------------
pause & exit
) else (
for /f "delims=" %%a in ('Type "%LogSearch%"') do (
@echo found file %%a
@Copy /Y %%a "%Destination%"
)
)
Start "" "%LogSearch%"

Geek-9pm

    Topic Starter

    Mastermind
  • Geek After Dark
  • Thanked: 1026
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: Help mefind and copy files in 'failed' list.
« Reply #5 on: March 16, 2017, 05:33:29 PM »
Hackoo,
WoW!
It took me awhile to research that. The quotes are from UNICODE. I copped it from a Linux server that gave me an error report when I tried to import some WordPress material I have posted on another web site.

“  201C
”  201D
They are called:
RIGHT DOUBLE QUOTE
LEFT DOUBLE QUOTE

But I could just use Notepad to change both into the ASCII double quire char 34
Let's say I just change are the UNICODE quotes tot he simple ASCII .
I will come back after dinner.  :)

Geek-9pm

    Topic Starter

    Mastermind
  • Geek After Dark
  • Thanked: 1026
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: Help mefind and copy files in 'failed' list.
« Reply #6 on: March 16, 2017, 08:33:37 PM »
All right, I just finished my dinner and the wife is watching TV.
Enclosed is a screenshot of my Windows XP system attempting to run the sample batch file you wrote for me. As you can see, I gave the batch file a name that would be easy for me to remember but not be in conflict with any other names used in the system. I named it SAGA.BAT and put it in my batch directory on the D drive.
The attached screenshot below shows that I get an error message when I try to run the SAGA batch file. After I hit the okay on the Windows error message there is one more line added to the output of the batch file. Here's the next output line.

The system cannot find the file D:\BAT\SAGA.txt.

So for some reason the program is trying to find itself, actually a text file that has its name. This would lead me to believe that is not reading anything from the file named TEST.TXT nor does it find anything from that file.
Looking at my blank  F: drive, I see it is still empty and nothing is been written to it.
Here's a copy of the test file. I've eliminated the Unicode characters and a shortened the test file to just a few items to help cut down on the amount of time it takes to go through the process once that it does get up and running.
Code: [Select]
Failed to import Media "fast-lleopard"
Failed to import Media "windows_tablet"
Failed to import Media "EpsonR300"
Failed to import Media "My-Destop"
Failed to import Media "teen_cell"
Failed to import Media "e-mail"
Failed to import Media "My-Destop"
Failed to import Media "wjy_linux"
Failed to import Media "SPAM"
Failed to import Media "chinaphones"

Also take note that when I send screenshot attachments to the forum,  I cut back on the amount of colors used and reduced the size of the image a little bit. By using the PNG type it cuts back quite a bit on the bandwidth and actually has a more crisp display that I'd use the JPEG type. The attachment is stored on the computer hope server and will become a permanent part of this thread.
I have not made any major changes to the batch file, I only added to the park for the source file and the start-up directory.
I am very very weak on for loops because the variables used in for loops are so cryptic a start to lose focus very easily.
Neither have any suggestions how I would get debug this script?
Thank you very much for your attention and for the suggestion.
Microphone off


[attachment deleted by admin to conserve space]

Hackoo



    Hopeful
  • Thanked: 42
  • Experience: Expert
  • OS: Windows 10
Re: Help mefind and copy files in 'failed' list.
« Reply #7 on: March 17, 2017, 07:44:15 AM »
Can you join me the original failed file ? because, i want to do some test on it !
So, we can make our script step by step  ;)
This piece of code try to extract all the words that are enclosed between the left and right double quote and replace them by a simple double quote.

Code: [Select]
@echo off
set "FailedLog=test.txt"
set "ExtractingWords=%~dp0ExtractingWords.txt
If exist "%ExtractingWords%" Del "%ExtractingWords%"
setlocal ENABLEDELAYEDEXPANSION
for /f "tokens=5 delims= " %%a in ('Type "%FailedLog%"') do (
Set "FileName=%%a"
Rem We subtitute Left and Right double quote if exist by ,
REM a simple double quote, and we save it into a file called ExtractingWords.txt
Set FileName=!FileName:“="!
Set FileName=!FileName:”="!
@echo !FileName! >> "%ExtractingWords%"
)
Start "" "%ExtractingWords%" & exit

So, please can you confirm me, if this code works or not on your windows XP, because, i just have tested it only on my windows 7

Geek-9pm

    Topic Starter

    Mastermind
  • Geek After Dark
  • Thanked: 1026
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: Help mefind and copy files in 'failed' list.
« Reply #8 on: March 17, 2017, 10:04:18 AM »
I have not yet tried your code to convert Unicode quotes to ASCI quote.
I will try that and get back  to you.
Meanwhile, the filed list I have enclosed below.
I removed the header and trailer.


[attachment deleted by admin to conserve space]

Geek-9pm

    Topic Starter

    Mastermind
  • Geek After Dark
  • Thanked: 1026
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: Help mefind and copy files in 'failed' list.
« Reply #9 on: March 17, 2017, 10:33:31 AM »
Well, it does indeed replace the Unicode with the ASCII char 34 qote.
But it did not do all items.
And I have no idea of how it works.
 

patio

  • Moderator


  • Genius
  • Maud' Dib
  • Thanked: 1769
    • Yes
  • Experience: Beginner
  • OS: Windows 7
Re: Help mefind and copy files in 'failed' list.
« Reply #10 on: March 17, 2017, 12:52:33 PM »
Quote
So, please can you confirm me, if this code works or not on your windows XP, because, i just have tested it only on my windows 7

If the code is written proper it would work in both...

I also think this Task is not clarified as any code is gonna treat folders differently than files...so clarification is needed ...
" Anyone who goes to a psychiatrist should have his head examined. "

Geek-9pm

    Topic Starter

    Mastermind
  • Geek After Dark
  • Thanked: 1026
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: Help mefind and copy files in 'failed' list.
« Reply #11 on: March 17, 2017, 01:20:05 PM »
Dictation.
Yes, I need to clarify what's going on. The list of failed files is really a list of media files, not folders. The failed files list is the output from WordPress off of the Linux server. It put the filenames inside of quotes that are used on UNIX and Linux systems. These quotes can easily be changed into the single quote used in the ASCII table. That part is not too hard.
Now here comes the hard part. Each file is the name of some type of media file. That means it could be an MP3, MP4 for some kind of picture. The pictures that I most often use would be of types JPEG, GIF and PNG.
And I have no idea where I put these files in my personal computer. So I was thinking you'd be easier to write some kind of batch file that would search all the directories in my data drive and see if I used any media files from my personal computer and uploaded them to my website server.
This error occurred when I moved my WordPress content from one web host to another web host. For some reason that I don't quite understand it did not deserve the media files. I was hoping that I could locate those files on my personal computer and then upload them again to my WordPress blog and maybe that would fix the problem.
Altogether about 70 media files that are missing. I'm quite sure all the files were of pictures and not of video. So let means that I would have to search for any file type and then match it with the literal name.
I suppose this would have to be done inside of some kind of for loop where the for loop would take the filename out from the list and then search through the entire drive to see if there is any file by that name with any kind of extension .
As mentioned earlier, duplications should not be an issue, so it would be okay just overwrite an existing file in the destination directory. In this case, the destination directory would be a blank partition that I had prepared just for this job.
The batch file to remove the UNIX quotes works fine even in Windows XP. But the other program to find and copy does not work right at all and I have no idea how to debug it.

End of dictation.

Hackoo



    Hopeful
  • Thanked: 42
  • Experience: Expert
  • OS: Windows 10
Re: Help mefind and copy files in 'failed' list.
« Reply #12 on: March 18, 2017, 02:23:37 AM »
Here is another way to convert the unicode double quotes Left [ChrW(8220)] and Right [ChrW(8221)] by, a simple double quote [ChrW(34)] using a vbscript !

Code: [Select]
@echo off
set "FailedLog=%~dp0failed1.txt"
set "ConvertedFile=%~dp0Converted.txt"
set "OutPutFile=%~dp0OutPutFile.txt"
If Exist "%OutPutFile%" Del "%OutPutFile%"
Set "Tmpvbs=%tmp%\%~n0.vbs"
(
echo Data = WScript.StdIn.ReadAll
echo Data = ReplaceString(Data^)
echo WScript.StdOut.WriteLine Data
echo '************************************************
echo Function ReplaceString(Data^)
echo Data = Replace(Data,ChrW(8220^),ChrW(34^)^)
echo Data = Replace(Data,ChrW(8221^),ChrW(34^)^)
echo ReplaceString = Data
echo End Function
echo '************************************************
)>"%Tmpvbs%"
Rem We replace the unicode double quotes Left [ChrW(8220)] and Right [ChrW(8221)] by,
Rem a simple double quote [ChrW(34)], and we save it
Rem into a file called Converted.txt
Call :ReplaceString %FailedLog% %ConvertedFile%
setlocal ENABLEDELAYEDEXPANSION
for /f "tokens=5 delims= " %%a in ('Type "%ConvertedFile%"') do (
Set "FileName=%%a"
echo !FileName!
echo !FileName! >> "%OutPutFile%"
)
pause & Start "" "%OutPutFile%" & exit
::***************************************
:ReplaceString <InputData> <OutPutData>
cscript /nologo "%Tmpvbs%" < "%~1" > "%~2"
If Exist "%Tmpvbs%" Del "%Tmpvbs%"
exit /b
::***************************************

For the hard part we should trying another way instead of using the command Where that is not implemented by default in the windows XP

Hackoo



    Hopeful
  • Thanked: 42
  • Experience: Expert
  • OS: Windows 10
Re: Help mefind and copy files in 'failed' list.
« Reply #13 on: March 19, 2017, 06:13:08 PM »
Here is another approach to search without using the command WHERE
Just give a try and tell me the results !
Code: [Select]
@echo off
Title Searching for a specific file name and copy them to a new location
Mode con cols=90 lines=30 & color 9E
set "FailedLog=%~dp0failed1.txt"
set "ConvertedFile=%~dp0Converted.txt"
set "OutPutFile=%~dp0OutPutFile.txt"
set "List=%~dp0%~n0_List.txt"
set "FoundFile=%~dp0%~n0FoundFile.txt"
set "SourceLocation=D:\"
set "Destination=F:\LostImage"
If not exist "%Destination%" MD "%Destination%"
If Exist "%OutPutFile%" Del "%OutPutFile%"
If Exist "%List%" Del "%List%"
If Exist "%FoundFile%" Del "%FoundFile%"
Cls
echo(
echo       --------------------------------------------------------------------------
echo              Please Wait a while ....... Searching is in progress .........
echo       --------------------------------------------------------------------------
set Count=0
Set "Tmpvbs=%tmp%\%~n0.vbs"
(
echo Data = WScript.StdIn.ReadAll
echo Data = ReplaceString(Data^)
echo WScript.StdOut.WriteLine Data
echo '************************************************
echo Function ReplaceString(Data^)
echo Data = Replace(Data,ChrW(8220^),ChrW(34^)^)
echo Data = Replace(Data,ChrW(8221^),ChrW(34^)^)
echo ReplaceString = Data
echo End Function
echo '************************************************
)>"%Tmpvbs%"
Rem We replace the unicode double quotes Left [ChrW(8220)] and Right [ChrW(8221)] by,
Rem a simple double quote [ChrW(34)], and we save it
Rem into a file called Converted.txt
Call :ReplaceString %FailedLog% %ConvertedFile%
setlocal ENABLEDELAYEDEXPANSION
for /f "tokens=5 delims= " %%a in ('Type "%ConvertedFile%"') do (
Set /a Count+=1
Set "FileName[!Count!]=%%a"
)

Rem We create a list file with extension jpg png gif
Set "Ext=jpg png gif"
for %%E in (%Ext%) do (
Dir /A-D /b /s "%SourceLocation%*.%%E"
)>> "%List%"

for /L %%i in (1,1,%Count%) do (
for /f "delims=" %%f in ('Type "%List%" ^|find /I !FileName[%%i]!') do (
if  "%errorlevel%" EQU "0" (
@echo "%%f"
@echo "%%f" >> "%FoundFile%"
@copy /y "%%f" "%Destination%"
)
)
)
Start "" "%FoundFile%" & pause & exit
::*****************************************
:ReplaceString <InputData> <OutPutData>
cscript /nologo "%Tmpvbs%" < "%~1" > "%~2"
If Exist "%Tmpvbs%" Del "%Tmpvbs%"
exit /b
::*****************************************