Informatica 10 - Delete files that have a space in the name - informatica-powercenter

How do you delete files with a space in the name?
I have a mapping that will update a table with the file names that fail the naming convention.
I use this table to create a .bat file to hold their names.
This is the code I run in a command to delete all the unwanted files. If works fine if the files do not have a space in the name:
$$DRIVE_MAIN & CD $$IN_FOLDER & for /F %A in (DELETE_list.dat) do del %A
If the file has a space in the name it does not work. I have tried to put double quotes around the file name as they get loaded into the table e.g. “Load ed_part1.csv”. So, when it gets written out to the .bat file it is “Load ed_part1.csv”.
Unfortunately it still wont get deleted.
What am I missing.
Cheers
C

try putting the double quotes in the script - not in the file:
$$DRIVE_MAIN & CD $$IN_FOLDER & for /F %A in (DELETE_list.dat) do del
“%A“

Related

Bash robocopy from text file containing path to folders and files to copy with special characters

I had a bash xcopy script, but got a lot of issues. After a lot of searching and reading I guess robocopy was a better tool to do the copy.
(The script must run on windows 10 computers without installing anything else and without internet access)
I'm trying to make a bash script that copy (with robocopy) some local network folders and files to a local custom directory. The aim is to be able to access to the files off from the local network.
The path to folders and files are stored inside a txt file (each line = a path)
I want to keep the structure of folder I save locally.
For example the folder X:\Path\to some\local\network\folder\with\some & characters\ will result in C:\PathTolocalFolder\Path\to some\local\network\folder\with\some & characters\ (without the X:\ letter)
Based on many similar questions (but not all at the same time) I have done this :
#echo off
SETLOCAL EnableDelayedExpansion
cls
cd C:
chcp 28591 > nul
for /f "delims=*" %%a in ('type "X:\path with spaces & specials characters\List.txt"') do (
REM echo %%a
REM echo !%%a!
echo %%a to C:\PathTolocalFolder!%%a!
ROBOCOPY "%%~a" "C:\PathTolocalFolder!%%a!" /S /A+:RA /R:1 /W:5
)
It is partially a success, but :
As there are special characters everywhere in paths and files names, I got some issues. Specially with & characters. My double quotes doesn't solve the problem. How could I go better?
For some cases, I want to save some files but not the whole directory where they are. The full path to the file is inside the text file. But as robocopy needs to add a space between folder path and file filter I have do some manipulation. How can I detect and extract the file name when there is one to adapt the robocopy command?
I want to use an exclusion list like I was doing before with xcopy. But robocopy doesn't accept a file in input for exclusions. I tried this to extract the exclusion file:
for /f "usebackq tokens*" %%D in ("C:\path to exclusion file\exclusions.txt") do (
if NOT "!dirs!"=="" (
Set dirs=!dirs! "%%D"
else (
Set dirs ="%%D"
)
)
But doesn't really know what I am doing and how to combine with the first part.
Bonus questions I'm using the robocopy log file functionality (removed from below) is there a way to archive (by adding the date in the name for example) previous log file before creating the new one? Is it possible to remove the progress percents in the log file but to display it in the terminal instead? How to use the "/np" option for log file but not for terminal display?
It's hard to me to understand how the delayed variables are working in batch files and how the different methods to read a file or variable are working.
Any help is welcome :)
Sorry for my bad English skills
thank for having read

Batch: Copy File from different Subfolders with certain file name to other destination

I am total beginner and need help with copying of files in windows. I have xlsx files in in different subfolders. The name of the files that I want to copy contain (but are not limited) to "Reporting Assessment Tool". I would like to copy all files containing that name and bring them to flat source destination (don't need the folder structure).
source: c:\users\name\desktop\upload
destination: c:\users\source\desktop\tool
So far I have tried the following
cd /D "c:\users\jubalkheimer\desktop\upload" #for /r %%a in ("*Reporting Assessment Tool.xlsx") do (
copy "%%a" "c:\users\jubalkheimer\desktop\tool\"%%~a")
I am not receiving a error message, but files don't get copied....
Can you help?
Many thanks
The batch file code for this task could be:
#echo off
for /R "%USERPROFILE%\desktop\upload" %%I in ("*Reporting Assessment Tool.xlsx") do (
copy /-Y "%%I" "%USERPROFILE%\desktop\tool\%%~nxI"
)
This could be done also with a single command line in batch file:
#for /R "%USERPROFILE%\desktop\upload" %%I in ("*Reporting Assessment Tool.xlsx") do #copy /-Y "%%I" "%USERPROFILE%\desktop\tool\%%~nxI"
The case-sensitive loop variable I holds on each loop run the name of a file with full path without surrounding double quotes found in the specified directory or any subdirectory of that directory matching the file name pattern *Reporting Assessment Tool.xlsx.
For copying the found file with prompting the user of the batch file for overwriting an already existing file with same name in target directory it is necessary to specify as first parameter the string assigned to the loop variable and as second parameter the target path and just file name and file extension of the found file without path. This explains the usage of "%%I" (file name with extension and full path enclosed in double quotes) and "Target Path\%%~nxI" (just file name and file extension with fixed destination path enclosed in double quotes) on COPY command line.
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
copy /?
echo /?
for /?
%USERPROFILE% references the predefined environment variable USERPROFILE which holds the path to profile directory of the current user account.
It would be very easily possible to do this task also without the usage of a batch file using Windows Explorer.
Navigate to folder %USERPROFILE%\desktop\upload
Run in that folder a search for *Reporting Assessment Tool.xlsx
Windows Explorer automatically searches recursive in that folder and all subfolders for files matching this file name pattern.
Select all found files with Ctrl+A (select All).
Prepare for copying all selected files with Ctrl+C (Copy).
Navigate to folder %USERPROFILE%\desktop\tool
Paste the files prepared for copying with Ctrl+V (Paste) which results in copying the files now.

Only conserve the name of the folder in a .txt file with a complete directory (Batch)

(I DIDN'T DO A BATCH WITH THIS STUFF YET)
I have a file called "worldcopy2.txt" which inside has a full directory:
C:\Users\Robert\Desktop\myworld2
And I want to create a batch file to change the inside of the .txt to only have the name of the last folder of the directory that be in the moment. For example:
If the .txt file says C:\Users\Robert\Desktop\funinside, the batch must change the .txt to say inside only funinside.
Must work with all the directories.
Translated with Google Translate.
I have tried this:
#echo off
setlocal
REM read a full path from file
type worldcopy2.txt
for /f %%F in (worldcopy2.txt) do set x=%%F
REM extract last path component and write it back to file
for %%P in ("%x%") do echo %%~nP> worldcopy2.txt
type worldcopy2.txt
Discard the type worldcopy2.txt statements after testing. The idea behind this is to treat the path as if it were a fully qualified filename and let the for loop extract the name. Note that this will fail if the foldername contains a dot (".").

Batch file with time issue before 10 AM

I have created a batch script to take a file, copy it to a folder with the date and time as the folder name and then to rename the file also based off the date and time. My issue is that any time before 10 AM, the command fails:
c:\ICVERIFY\ICWin420\DATADIR>md C:\SettlementReports\Settlement_Reports\DATADIR\
06-25-2014_ 709_08.24.txt
A subdirectory or file C:\SettlementReports\Settlement_Reports\DATADIR\06-25-201
4_ already exists.
Error occurred while processing: C:\SettlementReports\Settlement_Reports\DATADIR
\06-25-2014_.
Here is my batch file, I have put a time out right before it errors out.
cd c:\
cd icverify
cd icwin420
cd DATADIR
:: this is Regional settings dependent so tweak this according your current settings
Echo %DATE% %Time%
Set TDate=%date:~10,4%%date:~4,2%%date:~7,2% FOR %%V IN (%1) DO Rename %%V %%V%TDate%
md C:\SettlementReports\Settlement_Reports\DATADIR\%date:~4,2%-%date:~7,2%-%date:~10,4%_%time:~0,2%%time:~3,2%_%time:~6,5%.txt
timeout /T 1
copy ICRPT*.txt C:\SettlementReports\Settlement_Reports\DATADIR\%date:~4,2%-%date:~7,2%-%date:~10,4%_%time:~0,2%%time:~3,2%_%time:~6,5%.txt
cd c:\
cd Settlementreports
cd settlement_reports
cd datadir
cd %date:~4,2%-%date:~7,2%-%date:~10,4%_%time:~0,2%%time:~3,2%_%time:~6,5%.txt
ren ICRPT*.TXT ICRPT_%date:~4,2%-%date:~7,2%-%date:~10,4%_%time:~0,2%%time:~3,2%_%time:~6,5%.txt
Any help is greatly appreciated.
Your %time% variable contains a space instead of an initial 0 left padding the hours for hours less than 10:00. You can use
set "$time=%time: =0%"
to replace the space with a 0, storing the resulting value in a new variable. Then replace the references to %time% with the new variable %$time% as
md C:\ ....... \%date: ... %_%$time:~0,2%%$time:~3,2%_%$time:~6,5%.txt
Or instead, if the space is not a problem in your file names, quote all the file references to avoid the errors
md "C:\Settlem .... _%time:~6,5%.txt"
For any of the two options, do the change in all the commands in your file referencing files/folders
replacing the space with a 0 (see MC ND's answer) is one possibility.
But you should get used to put any <path>\file.ext into doublequotes.
copy file.txt new path\file with spaces.txt
is interpreded as copy file.txt to new, and there are additional parameters path\file, with and spaces.txt, which are not expected.
This syntax works better:
copy "file.txt" "new path\file with spaces.txt"
Here there are only two parameters, each enclosed in doublequotes.

Copying files from a list

I have a list of 4000 .tif images that I need copied from a folder containing 20,000+ images.
I am trying to use command prompt to do so by using code found from googling my problem.
the code is as follows:
for /f %a in H:\list.txt do copy %a H:\new
"H:\list.txt" is my list file
"H:\new" is where i want my files to be copied to
I am running this command in the file folder that contains the .tif files H:\Doc2 and I keep getting:
H:\list.txt was unexpected at this time.
What is causing the issue? Is my list not correctly set up?
It looks like this:
ABBA.TIF
ABBD.TIF
ABBQ.TIF
Do i need commas or colons after the file names?
H:\list.txt is a literal, you want to loop over each of the lines of the file. Check this out:
How do you loop through each line in a text file using a windows batch file?
for /F "tokens=*" %%A in (myfile.txt) do [process] %%A
Suggestion: tag this with "windows" as well.
Amir diagnosed your immediate problem - your code is missing the parentheses around the IN clause.
But you have another potential problem. Your list may include file names and or paths that contain spaces or other special characters. If so, then the name must be quoted.
The values in the list may already by quoted, or they may not. You can use the ~ modifier to strip any existing enclosing quotes that may or may not be there, and then explicitly add your own.
for /f %a in (H:\list.txt) do copy "%~a" H:\new
If you want to include the line in a batch file, then each % must be doubled as %%.

Resources