Excel file name changed dynamically - sql

I used an excel template. In my ssis package at first the template is copied in the working directory and package execute. In the next run the excel file which is already existed in the working directory it moved into BACKUP folder and again the template file copied. It works good.
But i want to do something when i move it i want to rename it like is the previous file name is Input_01 in the next move it will input_02. How can i do this?
i am using Execute process task toolbox in SSIS pacakge.
and a .bat file is called. in the .bat file i write
move "E:\InputFolder\Input.xls" "D:\Backup"
copy "E:\Template\Input.xls" "E:\InputFolder\Input.xls"
I want a ouput in the backup folder the excel files are like
Input_01,Input_02.... what will be my command?

Here's how to do it with a batch file:
#echo off
set cnt=1
for /f %%f in ('dir /b "D:\Backup\Input_*.xls"') do set /a cnt+=1
if %cnt% lss 10 (move "E:\InputFolder\Input.xls" "D:\Backup\Input_0%cnt%.xls") else (move "E:\InputFolder\Input.xls" "D:\Backup\Input_%cnt%.xls")
copy "E:\Template\Input.xls" "E:\InputFolder\Input.xls"
You can have more control over your files' naming convention (not to mention deletion of old files) if you use a Script Task, though.

can we use a 'File system task' instead. It helps us Renaming a file. You will have to use a 'For-Each loop Container' as well.

Related

Would like to run an Excel macro with drag and drop

I have a macro that asks the user to choose an excel file and then outputs two text files based on the data.
I am looking for a way to just drop the excel file onto the macro file and have it process without the need for opening the macro file, a command button, an open file dialog, etc. I would like to drop the file on the other file and just have the two text files output.
I saw something that looked promising using a VBS file, but was unable to get it to work.
Here's the bare bones of what you need to do:
Wscript.echo "Begin..." 'just letting you know it's working
Set objArgs = Wscript.Arguments 'capture arguments; arg 0 is the name of the dropped file
Wscript.echo "The file name you dropped is:" & objArgs(0)
'DO STUFF TO THE FILE HERE
Wscript.echo "...Finished" 'all done
Save this to a file with a "vbs" extension.
Drag and drop a file onto it.
If your Windows file associations are properly setup,
you'll see this output a message for each of the wscript.echo
lines.

Copy whole folder except one sub folder

I want to copy one folder which has many sub folders to another directory/drive.I just don't want to copy one sub directory.This is what i am planning to do but with this i am getting an error except is not an internal or external command .
except "D:\Splunk\var" xcopy "D:\Splunk" "D:\test\Splunk_Withoutdata\%CurrentDate%\" /s
Thanks
VG
I have achieved it myself this is what i have done .I used Exclude command rather except .
xcopy "D:\Splunk" "D:\test\Splunk_Withoutdata\%CurrentDate%\" /EXCLUDE:D:\batch\list.txt /s
under list.txt I have mentioned the folder name which I want to exclude like var\.

Excel error when using path name as parameter from command line

I am trying to launch a specific Excel document from the command line and pass in a variable in the form of a file path. On starting the Excel sheet runs a macro. This file path may contain spaces however when Excel interprets this it, I believe it tries to open up each section after a space as a new workbook. This results in a number of error warnings after the program runs as it obviously cannot file created from the substring.
The batch file looks like this
echo %~1
start excel.exe %USERPROFILE%\Desktop\Compare.xlsm /e/%1%
pause
EDIT: For Clarification. The batch file is activate when a file is drag and dropped onto it. The path of the file dropped is then stored in the %1 variable. If this file path has spaces then after each space Excel assumes that this is a new worksheet and tries to open it. The call to the Compare.xlsm which contains a macro that is going to use the path of the dragged file works correctly as it will always be on the desktop. My issue therefore is how to get Excel to take the entire path name stored in %1 and use it as one command line parameter rather than several calls to open new workbooks.
If the file that is used on the batch file does not contain any spaces then the errors do not occur. Is there any way of getting rid of the errors when using a file path that might have spaces e.g. C:\Users\My Documents\foobar.txt
Try this (TRIED AND TESTED)
echo %~1
start "excel.exe" "%USERPROFILE%\Desktop\Compare.xlsm" /e/%1%
pause
Notice the quotes around "Excel.Exe" and the file path?
Another example
echo %~1
start "excel.exe" "%USERPROFILE%\Desktop\Blah Blah.xlsm" /e/%1%
pause
I am assuming that you are running the code from a .Bat file
as Sid says, any paths that contain spaces must be quoted.
so to use a pth such as C:\My Documents\fubar.txt you would have this:
"C:\My Documents\fubar.txt"
and in your example:
echo
%~1
start excel.exe "%USERPROFILE%\Desktop\Compare.xlsm" /e/%1%
pause
EDIT:
When using a variable as the path, you need to include the quotes in the variable!

VBA script to create dir and file

I would like to create directory folders and files using excel VBA script. I have the following String
/path/project/command.exe
And I create folders and file under drive D:\ likes this D:\path\project\command.exe.My file may be vary .exe or .txt or .doc or etc.. I already used MkDir but I only create folder not create file. So help me to create directory folders and files using excel VBA script. If exe file or some file types that are not create from vba, I only need to create some temporary files for replacement of exe file.
If you want to create blank files you could use cmd's fsutil:
Sub createBlankFile()
Shell "fsutil file createnew ""D:\path\project\command.exe"" 0", vbNormalFocus
End Sub
The 0 refers to the size of the file.

Batch File with User Input, Rename and Copy to a different Location

I have a large amount of files to Rename based on User input variable and then copy to a specific location. Below is a sample of what I have thus far. It appears as though the Set /p is recognized in the Rename command by not when it goes to Copy it to the new dir. Any help would be appreciated.
#Echo OFF
Echo "Blahhh Rename and Copy. Press Enter."
Pause
SET /p SN=EnterServerName-
Echo You Entered - %SN%
Pause
Rename C:\ctemp\WorkingCSRs\key.pem %SN%_Key.bin
Copy C:\ctemp\WorkingCSRs\Certificates\%SN%_Key.bin C:\ctemp\WorkingCSRs\Certificates\folder /y
You're renaming in C:\ctemp\WorkingCSRs, but the renamed file is expected to be in C:\ctemp\WorkingCSRs\Certificates when copying.
Also you could do the copy as (assuming you don't need the file to be renamed):
Copy C:\ctemp\WorkingCSRs\key.pem C:\ctemp\WorkingCSRs\Certificates\folder\%SN%_Key.bin /y