KSK_R_D
(KSK R&D)
January 25, 2024, 3:52am
1
Hi everyone, i’m facing this problem.
I have an excel file like this
With each row of the column C, from C3, i want to get the text from the cell and use it to rename my pdf files
I managed to read and display the text from excel to message box but i can’t rename to my pdf files. Hope anyone would help with this
Yoichi
(Yoichi)
January 25, 2024, 3:56am
2
Hi,
Is the above image input files? Can you also share output file name and rule of renaming in details?
It seems there are multiple same project number in the sheet.
Regards,
KSK_R_D
(KSK R&D)
January 25, 2024, 4:00am
4
yeah, the output file name is the name read from column C. For example, C3 gives F1299163-03-X01 so the pdf file named EFAKK_231206-1447-01 will become F1299163-03-X01
mkankatala
(Mahesh Kankatala)
January 25, 2024, 4:03am
6
Hi @KSK_R_D
You have the 5 files you want to rename the file names with the first five rows right.
1 Like
KSK_R_D
(KSK R&D)
January 25, 2024, 4:05am
7
i took 5 files and 5 rows for example, the amount is unpredictable, they can be more or less
Yoichi
(Yoichi)
January 25, 2024, 4:11am
8
Hi,
Can you try the following sample? This renames files under “files” folder in project folder.
dict = dt.AsEnumerable.ToDictionary(Function(r) r(1).ToString+"-"+System.Text.RegularExpressions.Regex.Match(r(2).ToString,"\d+$").Value,Function(r) r(2).ToString)
Sample
Sample20240125-2.zip (305.6 KB)
Regards,
1 Like
KSK_R_D
(KSK R&D)
January 25, 2024, 4:13am
9
thanks, i’ll try and tell you the result later
Yoichi
(Yoichi)
January 25, 2024, 5:49am
11
Hi,
For now, can you try to save the workflow, then close Studio and re-open this project? Automatic recovery may run.
Regards,
1 Like
KSK_R_D
(KSK R&D)
January 25, 2024, 5:52am
12
oh, i mean, your code ran perfectly, but when i write it to my program, it becomes an error
Yoichi
(Yoichi)
January 25, 2024, 5:55am
13
Yep, Sometimes this error occurs when lacking refernce. Doesn’t the above solution solve the matter?
1 Like
KSK_R_D
(KSK R&D)
January 25, 2024, 5:56am
14
yeah it solved my problem, but can you explain a little about it, i’m quite confusing right now
Yoichi
(Yoichi)
January 25, 2024, 5:58am
15
Which details do you need, file operation or reference problem?
If file operation, the following may help you.
First, we create Dictionary which key is input filename without extension such as EFAKK_231206-1447-01 and value is renamed filename such as F1299163-03-X01 (品番) from excel data in advance.
The key is created from PROJECT No. and last 2 digits of 品番 using the following exprssion
r(1).ToString+"-"+System.Text.RegularExpressions.Regex.Match(r(2).ToString,"\d+$").Value
The value is created from 品番
Next iterate the target folder and process each pdf file
the following expression returns renamed string from CurrentFile using the above dictionary.
dict(System.IO.Path.GetFileNameWithoutExtension(CurrentFile.Name))+CurrentFile.Extension
Hope this helps you.
Regards,
1 Like
KSK_R_D
(KSK R&D)
January 25, 2024, 6:13am
16
1 Like
system
(system)
Closed
January 28, 2024, 6:13am
17
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.