الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

كيف اضيف التاريخ بجوار اسم الملف

بدأه makrm في 10 نوفمبر 2014 · 7 رد · 1,050 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع
السلام عليكم 

 

يوجد لدي فولدر به اكثر من 10 الاف ملف (PDF)  وكل ملف له اسمه الخاص اريد اضافة التاريخ بجور اسمه

 

 

ولكم جزيل الشكر وارحترام

#2

استخدم vbscript

 

هذا مثال على تسمية الصور داخل مجلد واحد بناء على اسماء موجودة فى ملف نصي يسمي names.txt

' findheader.vbs
Option Explicit
'--------------------------------------------------------
Dim oFSO,oFolder,oNamesFile,oFile,oLine
Dim sText,sFolder
'--------------------------------------------------------
Const ForReading            = 1
Const ForWriting            = 2
Const ForAppending          = 8
'--------------------------------------------------------
Const TristateUseDefault    = -2
Const TristateTrue          = -1
Const TristateFalse         = 0
'--------------------------------------------------------
Set oFSO = CreateObject("Scripting.FileSystemObject")
sFolder = oFSO.GetParentFolderName(WScript.ScriptFullName)
sText = oFSO.BuildPath(sFolder,"names.txt")
Set oNamesFile = oFSO.GetFile(sText)
sFolder = BrowseFolder(sFolder,True)
'--------------------------------------------------------
If Not oFSO.FileExists(oNamesFile) Then
    MsgBox "الملف المسمى names.txt غير موجودبجوار البرنامج",16 + 4096,"Error"
    WScript.Quit
End If
'--------------------------------------------------------
If sFolder = "" Then
    MsgBox "يجب عليك اختيار المجلد الذى يحتوى على الصور التى تريد اعادة تسميتها",16 + 4096,"Error"
    WScript.Quit
End If

If oFSO.FolderExists(sFolder) Then
    Set sFolder = oFSO.GetFolder(sFolder)
    SearchFolder oFSO,sFolder
End If
'--------------------------------------------------------
Sub SearchFolder(oFileSystemObject,sFolderObject)
    Dim oTextStream
    Dim oLine,oUpperLine
    Dim iLine,iCount
    Dim sExt
    Dim oDict
    '-----------------------------------
    Set oDict =  CreateObject("Scripting.Dictionary")
    Set oTextStream = oNamesFile.OpenAsTextStream(ForReading)
    iLine = 0
    Do Until oTextStream.AtEndOfStream
            oLine = oTextStream.ReadLine
            If Len(oLine) > 0 Then
                oDict.Add iLine,oLine
                iLine = iLine + 1
            End If  
    Loop
    'WScript.Echo oDict.Item(0)
    oTextStream.Close
    '-----------------------------------
    iCount = 0
    For Each oFile In sFolderObject.Files
        'WScript.Echo oFile.Name
        sExt = GetFileExtension(oFile.Path)
        If sExt = ".JPG" Then
            If iCount < iLine Then
                oFile.Name = oDict.Item(iCount) & ".jpg"
                iCount = iCount + 1
            End If
        End If
    Next
    
End Sub
'--------------------------------------------------------
Function GetFileExtension(sFileName)
    Dim iDot
    iDot = InStrRev(sFileName,".",-1,1)
    If iDot > 0 Then
        GetFileExtension = UCase(Mid(sFileName,iDot)) ' UPPER CASE
    Else
        GetFileExtension = ".JPG"
    End If
End Function
'---------------------------------------------------------
Function BrowseFolder( myStartLocation, blnSimpleDialog )
' This function generates a Browse Folder dialog
' and returns the selected folder as a string.
'
' Arguments:
' myStartLocation   [string]  start folder for dialog, or "My Computer", or
'                             empty string to open in "Desktop\My Documents"
' blnSimpleDialog   [boolean] if False, an additional text field will be
'                             displayed where the folder can be selected
'                             by typing the fully qualified path
'
' Returns:          [string]  the fully qualified path to the selected folder
'
' Based on the Hey Scripting Guys article
' "How Can I Show Users a Dialog Box That Only Lets Them Select Folders?"
' http://www.microsoft.com/technet/scriptcenter/resources/qanda/jun05/hey0617.mspx
'
' Function written by Rob van der Woude
' http://www.robvanderwoude.com
    Const MY_COMPUTER   = &H11&
    Const WINDOW_HANDLE = 0 ' Must ALWAYS be 0

    Dim numOptions, objFolder, objFolderItem
    Dim objPath, objShell, strPath, strPrompt

    ' Set the options for the dialog window
    strPrompt = "اختر المجلد الموجود بداخله الصور"
    If blnSimpleDialog = True Then
        numOptions = 0      ' Simple dialog
    Else
        numOptions = &H10&  ' Additional text field to type folder path
    End If

    ' Create a Windows Shell object
    Set objShell = CreateObject( "Shell.Application" )

    ' If specified, convert "My Computer" to a valid
    ' path for the Windows Shell's BrowseFolder method
    If UCase( myStartLocation ) = "MY COMPUTER" Then
        Set objFolder = objShell.Namespace( MY_COMPUTER )
        Set objFolderItem = objFolder.Self
        strPath = objFolderItem.Path
    Else
        strPath = myStartLocation
    End If

    Set objFolder = objShell.BrowseForFolder( WINDOW_HANDLE, strPrompt, _
                                              numOptions, strPath )

    ' Quit if no folder was selected
    If objFolder Is Nothing Then
        BrowseFolder = ""
        Exit Function
    End If

    ' Retrieve the path of the selected folder
    Set objFolderItem = objFolder.Self
    objPath = objFolderItem.Path

    ' Return the path of the selected folder
    BrowseFolder = objPath
End Function
'--------------------------------------------------------
WScript.Echo "Done successfully"


﴿وَمَا كَانَ اللَّهُ لِيُعَذِّبَهُمْ وَأَنْتَ فِيهِمْ ۚ وَمَا كَانَ اللَّهُ مُعَذِّبَهُمْ وَهُمْ يَسْتَغْفِرُونَ﴾

الأنفال ۳۳                                  
 

#3

متشكر جدااا 

علي اهتمامك وردك  سوال هل الجافا متقدرش تقوم بكده  و والكوده خاص بفيجوال بيسك 6 ولا دوت نت 

واكتر من متشكر

#4
اقتباس

 

متشكر جدااا 

علي اهتمامك وردك  سوال هل الجافا متقدرش تقوم بكده  و والكوده خاص بفيجوال بيسك 6 ولا دوت نت 

واكتر من متشكر

 

 

جافا تقدر طبعا

import java.io.File;

public class Main {
   public static void main(String[] args) {
      File oldName = new File("C:/program.txt");
      File newName = new File("C:/java.txt");
      if(oldName.renameTo(newName)) {
         System.out.println("renamed");
      } else {
         System.out.println("Error");
      }
   }
}

قم بانشاء كائن جديد مستخدما مسار المجلد الذي يحتوى على ملفات ال pdf

 

ثم قم باستدعاء الدالة listFiles من هذا الكائن

 

https://docs.oracle.com/javase/7/docs/api/java/io/File.html#listFiles()

وقم باستدعاء الدالة renameTo على كل ملف من المصفوفة السابقة الناتجة من استخدام الدالة السابقة

 

ملحوظة هامة :

الكود بالجافا سيكون أقصر وأسهل بكثير جدا من كود vbscript المرفق فى الرد السابق

تم تعديل هذه المشاركة بواسطة MOHAMED FATHEI في 11 نوفمبر 2014 في 19:03


﴿وَمَا كَانَ اللَّهُ لِيُعَذِّبَهُمْ وَأَنْتَ فِيهِمْ ۚ وَمَا كَانَ اللَّهُ مُعَذِّبَهُمْ وَهُمْ يَسْتَغْفِرُونَ﴾

الأنفال ۳۳                                  
 

#5

الف كلمة شكر لحضرتك بصراحة انا عاملت البرنامج بالــ vb6 وانا شايف ان الجافا اقصر منه بكتيررر 

انا مش فاهم اذاي بيقولو ان vb6 اكثر انتاجية

#6

هذا ليس الكود كاملا

 

ولكن ينقصه القليل


﴿وَمَا كَانَ اللَّهُ لِيُعَذِّبَهُمْ وَأَنْتَ فِيهِمْ ۚ وَمَا كَانَ اللَّهُ مُعَذِّبَهُمْ وَهُمْ يَسْتَغْفِرُونَ﴾

الأنفال ۳۳                                  
 

#7

هذا حلي المتواضع لمشكلتك . 

output : example_21_11_2014.pdf

 public static void main(String[] args) {

        File file = new File(FILE_PATH);
        File listFiles[] = file.listFiles();

        Date date = new Date();
        String format = new SimpleDateFormat("dd_MM_YYYY").format(date);

        // rename
        for (File f1 : listFiles) {

            String fullNameOfFile = f1.getName();
            String[] parts = fullNameOfFile.split("\\.");
            
            String  newFileName = parts[0]; // firstName

            // adding date to FistName
            newFileName += "_" + format;

            // extract extenstion index
            int indexOfExtenstion = fullNameOfFile.lastIndexOf(".");

            // adding extension to FullName (firstName_date.extenstion)
            newFileName += fullNameOfFile.substring(indexOfExtenstion);

            File theNewFile = new File(FILE_PATH + "\\" + newFileName);
            f1.renameTo(theNewFile);

        }

    }
1
#8

الف شكر الي ردكم  واهتمامك

متشكر استاذاي محمد فتحي 

وشكرا للاستاذ فهد

2

مواضيع مشابهة